Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
browser automation

How to Load Google Translate Scripts Reliably with Puppeteer

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Puppeteer’s page.addScriptTag() to insert a script, then wait for a page condition that proves the result you need has happened. Insertion, network quiet, and completed translation are three different things. A successful call to addScriptTag() does not by itself mean asynchronous script work is finished, and networkidle does not prove that a page has been translated.

There is an important boundary: Google documents ways for people to translate websites and a Cloud Translation API for application integrations, but the official material covered here does not establish a supported, general-purpose recipe for loading Google’s website-translation script manually with Puppeteer. The pattern below shows how to load an authorized script reliably without presenting an undocumented Google script URL or internal browser detail as a stable interface.

What “loaded reliably” means in Puppeteer

A script can be present in the document and have finished downloading while its work is still underway. For example, it may start asynchronous requests, update the DOM later, or fail to produce the application state you expected. Treat these as separate checkpoints:

  • Inserted: Puppeteer added a script element to the page.
  • Loaded: the browser fetched and evaluated the external script, subject to the page’s policies and the script’s behavior.
  • Completed for your use case: the page reached a meaningful state, such as an application-owned marker indicating that translated content is ready.

For reliable automation, define the last checkpoint before writing the wait. If you control the page, expose a clear state for the automation to observe. If you do not control it, identify a stable, visible result that actually demonstrates the outcome you need. Do not substitute the mere existence of a script tag for that result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Load an authorized script and wait for an explicit result

Puppeteer’s Page API supports adding a script by URL or by content. The example uses a URL placeholder on purpose: supply a script URL that you are authorized to load and that your application supports. It does not identify a Google Translate script URL.

The page in this example is assumed to set window.appTranslationState = 'ready' when its own translation work is complete. Replace that predicate with a state your application owns. The code uses ES modules and the Puppeteer package.

import puppeteer from 'puppeteer';

const targetUrl = 'https://your-site.example/page';
const authorizedScriptUrl = 'https://your-site.example/assets/translation.js';
const timeoutMs = 15_000;

const browser = await puppeteer.launch({ headless: true });

try {
  const page = await browser.newPage();
  page.setDefaultNavigationTimeout(timeoutMs);

  await page.goto(targetUrl, { waitUntil: 'domcontentloaded' });

  try {
    await page.addScriptTag({ url: authorizedScriptUrl });
  } catch (error) {
    throw new Error(`Could not insert or load the script: ${error.message}`);
  }

  try {
    await page.waitForFunction(
      () => window.appTranslationState === 'ready',
      { timeout: timeoutMs }
    );
  } catch (error) {
    throw new Error(
      `The script was added, but the page did not report translation ready within ${timeoutMs} ms. ` +
      `Check the script, its runtime errors, and the completion condition. ${error.message}`
    );
  }

  console.log('Application reports translation ready.');
} finally {
  await browser.close();
}

Use page.addScriptTag({ content: '…' }) instead if you need to inject content you control rather than fetch an external URL. Keep the same principle: successful insertion is not proof that asynchronous work triggered by that content has completed. A completion signal should describe the result your application needs, not merely an implementation detail such as “the callback ran.”

Choose the right navigation checkpoint

page.goto() accepts navigation wait conditions. Starting with domcontentloaded can be appropriate when the script can be added once the document has been parsed and you have a separate, explicit wait for the result. If the page’s own setup must run first, wait for the relevant application element or state before adding the script. Pick the condition based on the page’s dependency order; no single navigation event means that every script or application task is complete.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a bounded, meaningful wait

page.waitForFunction() evaluates a predicate in the page context until it becomes truthy or the timeout expires. The example makes the timeout explicit and treats timeout as a real failure, rather than continuing with a possibly untranslated page. Set the predicate to a state that can only occur when the result you care about is ready. If translation can fail, consider having the application expose a separate failure state so the automation can report a useful error instead of waiting until the timeout.

Why networkidle does not mean translation is done

page.waitForNetworkIdle() waits for a period with sufficiently little network activity according to Puppeteer’s network-idle behavior. That can be useful as a supporting observation when a page makes a finite set of requests. It is not a semantic completion signal: a script may finish its network requests before updating the page, a page may become quiet even though an expected operation failed, or background activity may prevent the network from becoming quiet at all.

When you do use it, give it a bounded timeout and follow it with the actual result check:

await page.waitForNetworkIdle({ timeout: 10_000 }).catch(() => {
  // Network quiet did not occur in time; do not treat that alone as success.
});

await page.waitForFunction(
  () => window.appTranslationState === 'ready',
  { timeout: 15_000 }
);

This pattern makes the distinction explicit: network idleness may inform the flow, but only the application’s readiness condition satisfies the translation requirement. If the page continually polls, opens a persistent connection, or loads background resources, omit the network-idle wait and rely on a suitable result condition instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can Puppeteer translate a webpage with Google Translate?

Puppeteer can automate a browser and insert scripts through its documented Page API. That does not make every script a supported Google integration. The official sources covered for this topic do not establish a general-purpose, supported method for manually loading Google’s website-translation script with Puppeteer. Avoid building production automation around guessed script URLs, internal globals, or details observed in a particular browser version.

For a person translating a website

Google Help describes a user-facing Websites flow for opening a website through Google Translate. It also says academic institutions and government, nonprofit, or non-commercial websites may be eligible to sign up for the Website Translator shortcut. That is conditional eligibility, not a blanket offer to every site. If your goal is simply to read a site in another language, use the user-facing route rather than trying to recreate it with browser internals.

For translation built into an application

Google documents Cloud Translation as a programmatic service with Basic and Advanced editions. That is a distinct integration path from automating a browser’s website-translation experience. Google’s attribution requirements say: “Applications using the Cloud Translation API must state in the application description and help documentation that Google Translate is used to power translation within the application and provide links to the Cloud Translation site.” If you use the API, account for that obligation in both places. The cited documentation does not establish pricing, language coverage, or performance for your particular application, so evaluate those details against the current product documentation for the edition you plan to use.

Do not confuse Chrome’s feature with a Puppeteer contract

Chromium’s translation design document describes a browser-controlled flow in which Chrome obtains a script after a user requests translation, injects it, and checks for success or failure. It also discusses caching and refetch behavior for the implementation it covers. This is architectural context, not a stable public script interface or a current Puppeteer integration contract. Browser internals can change; a description of how a browser feature works does not establish that an application should reproduce it by manually loading an internal resource.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot script loading and completion

  • addScriptTag() rejects: Check that the URL is valid and reachable from the browser process, the host responds with a script resource, and the target page’s security policy permits the load. Inspect browser console and page errors, and confirm the page has reached the point where you intend to insert the script.
  • The call succeeds but the result never appears: The script may have loaded without completing its asynchronous work, may have encountered a runtime error, or may not support the page. Check the console, network requests, and the application’s own state. Make the wait condition match the actual result rather than the script element.
  • The wait condition times out: Verify that the page can set the state you are waiting for, that the predicate uses the correct name and value, and that the script’s work is triggered. Distinguish a genuine failure state from a slow operation; adjust the timeout only when the page’s expected behavior justifies it.
  • networkidle times out: Persistent requests, polling, or background resources may keep activity going. If network quiet is not itself required, remove that wait and wait for a specific page result instead.
  • The script works locally but not on the target page: Compare the page’s security restrictions, authentication, request headers, cookies, and execution timing. A script permitted on a development page may be blocked or behave differently on another origin. Do not assume a browser’s own translation feature can be invoked through the same route.
  • Automation reports success too early: Strengthen the predicate. For example, wait for a translated-state flag or a specific translated element, not a generic page load event or a nonempty script element.

Or skip the browser setup

If the goal is to capture a page after your own browser automation has prepared it, ScreenshotNeo is a screenshot API rather than a translation service: it does not replace the translation step. Its API takes one GET request for a screenshot or PDF. The request below captures a page directly; it does not load Google Translate or certify that a translation finished. See the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. It also offers an MCP server for AI agents, and the free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.

Make the integration dependable

  • Keep the distinction between script insertion and task completion visible in the code and logs.
  • Wait on a semantic condition the application owns whenever you can; make timeouts explicit and actionable.
  • Use network-idle status only when it helps your particular page, never as a substitute for proof of translation.
  • Choose a documented integration surface for the actual requirement: a user-facing website flow for people, or a translation API for application-owned translation.
  • Treat browser translation internals as implementation context, not a promise that manually injecting a Google script will remain supported.

Frequently Asked Questions

Does `addScriptTag()` wait for a script’s asynchronous translation work to finish?

No. It handles script insertion; wait separately for an application-level condition that represents the completed result.

Can I use the same completion predicate on every site?

No. A predicate such as `window.appTranslationState` is illustrative and must be replaced with a state or visible result that the page you control actually provides.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.