Skip to content


Chrome DocsFirefox Docs

Refer to the browser docs above for basics on how the API works.

Execute Script Return Values

When using browser.scripting.executeScript, you can execute content scripts or unlisted scripts. To return a value, just return a value from the script's main function.

// entrypoints/background.ts
const res = await browser.scripting.executeScript({
  target: { tabId },
  files: ['injected.js'],
console.log(res); // "Hello John!"
// entrypoints/injected.js
export default defineContentScript(() => {
  console.log('Script was injected!');
  return 'Hello John!';