question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

exposeFunction fails with Firefox

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 4.0.1
  • Platform / OS version: Mac OSX Catalina 10.15.1
  • URLs (if applicable): n/a
  • Node.js version: 14.4.0

What steps will reproduce the problem?

Please include code that reproduces the issue.

Run the following script:

const puppeteer = require('puppeteer');

const firefoxOptions = {
  product: 'firefox',
  headless: false,
  extraPrefsFirefox: {},
  dumpio: true,
};

const browser = await puppeteer.launch(firefoxOptions);

const page = await browser.newPage();
await page.goto('https://news.ycombinator.com/');

await page.exposeFunction('test', () => {
  console.log('works!!!!');
});

What is the expected result?

Should work.

What happens instead?

Fails:

1593203097312	RemoteAgent	ERROR	UnknownMethodError: Runtime.addBinding:
	RemoteAgentError@chrome://remote/content/Error.jsm:25:5
	UnknownMethodError@chrome://remote/content/Error.jsm:108:7
	execute@chrome://remote/content/domains/DomainCache.jsm:96:13
	receiveMessage@chrome://remote/content/sessions/ContentProcessSession.jsm:86:45
caused by: 
(node:5070) UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.addBinding): Runtime.addBinding RemoteAgentError@chrome://remote/content/Error.jsm:25:5
UnknownMethodError@chrome://remote/content/Error.jsm:108:7
execute@chrome://remote/content/domains/DomainCache.jsm:96:13
receiveMessage@chrome://remote/content/sessions/ContentProcessSession.jsm:86:45

    at ~/node_modules/puppeteer/lib/Connection.js:156:63
    at new Promise (<anonymous>)
    at CDPSession.send (~/puppeteer/lib/Connection.js:155:16)
    at Page.exposeFunction (~/node_modules/puppeteer/lib/Page.js:391:28)
    at Page.<anonymous> (~/node_modules/puppeteer/lib/helper.js:117:27)
    at ~/test.cjs:37:14
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5070) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5070) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
0xba1acommented, Jul 12, 2020

+1

1reaction
sublimatorcommented, Mar 7, 2022

Any update on this ? This worked on puppeteer-firefox iirc Doesn’t work now? Works on playwright

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Firefox addon expose chrome function to website
So I have to use Cu.exportFunction, ok it works, but then when adding content, unsafeWindow, window or anything as context jpm run throw...
Read more >
Sharing objects with page scripts - Mozilla - MDN Web Docs
As the content scripts guide notes, content scripts don't see changes made to the DOM by scripts loaded by web pages.
Read more >
Developers - exposeFunction fails with Firefox -
Steps to reproduce. Tell us about your environment: Puppeteer version: 4.0.1; Platform / OS version: Mac OSX Catalina 10.15.1; URLs (if applicable): n/a ......
Read more >
api(popup): introduce BrowserContext.exposeFunction ...
When called, the function executes `playwrightFunction` in node.js and returns a [Promise] which resolves to the return value of `playwrightFunction`.
Read more >
playwright-firefox/api.md
The CDN for playwright-firefox. ... 100, might fail if the selector doesn't match any nodes during the given ... exposeFunction('md5', text => crypto....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found