Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling a exposed function inside an evaluateOnNewDocument function does not work on Chrome 70 #3106

Closed
williamoliveira opened this issue Aug 17, 2018 · 4 comments · Fixed by #3153

Comments

@williamoliveira
Copy link

  • Puppeteer version: 1.7.0
  • Platform / OS version: Linux x64
  • Node.js version: v10.0.0

This code works on Chorme/Chromium 69, "Hello from logExposedFunction1" and "Hello from logExposedFunction2" are logged to console, with Chrome 70 only "Hello from logExposedFunction2" is logged.

I noticed logging logExposedFunction1 logs ƒ () { [native code] } and logExposedFunction2 logs a js code from __puppeteer_evaluation_script__:2

Was there an API change around this? I did not see anything at the change log

const puppeteer = require('puppeteer')

const start = async () => {
  const browser = await puppeteer.launch({
    headless: false,
  });

  const page = await browser.newPage();

  await page.exposeFunction('logExposedFunction1', () => {
    console.log('Hello from logExposedFunction1')
  })
  await page.evaluateOnNewDocument(() => {
    logExposedFunction1()
  })

  await page.goto('https://example.com');

  await page.exposeFunction('logExposedFunction2', () => {
    console.log('Hello from logExposedFunction2')
  })
  await page.evaluate(() => {
    logExposedFunction2()
  })
}

start()
@williamoliveira
Copy link
Author

Just noticed delaying execution of logExposedFunction1() works, so there must be a race condition going on

 // ....
  await page.evaluateOnNewDocument(() => {
    setTimeout(() => {
      logExposedFunction1()
    }, 1)
  })
 // ....

I can move on with my life now but still would like to know If I am doing something wrong or is it a bug

@aslushnikov
Copy link
Contributor

Thanks @williamoliveira,

That's a recent regression; the offender is https://crrev.com/578514
We'll have to fix this upstream.

@aslushnikov
Copy link
Contributor

@williamoliveira
Copy link
Author

Awesome! thanks for the rapid work

aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Aug 23, 2018
This roll includes:
- https://crrev.com/584293 - DevTools: execute scripts in addScriptToEvaluateOnLoad in order

Fixes puppeteer#3106.
aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Aug 28, 2018
This roll includes:
- https://crrev.com/584293 - DevTools: execute scripts in addScriptToEvaluateOnLoad in order
- https://crrev.com/585630 - DevTools: introduce Browser.grantPermissions

References puppeteer#846.
Fixes puppeteer#3106.
aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Aug 29, 2018
This roll includes:
- https://crrev.com/584293 - DevTools: execute scripts in addScriptToEvaluateOnLoad in order
- https://crrev.com/585630 - DevTools: introduce Browser.grantPermissions
- https://crrev.com/587156 - Revert "[Base] Use background mode for ThreadPriority::BACKGROUND threads (behind feature) (reland)."

The "revert" patch fixes headless functionality on windows.

References puppeteer#846.
Fixes puppeteer#3106.
aslushnikov added a commit that referenced this issue Aug 30, 2018
This roll includes:
- https://crrev.com/584293 - DevTools: execute scripts in addScriptToEvaluateOnLoad in order
- https://crrev.com/585630 - DevTools: introduce Browser.grantPermissions
- https://crrev.com/587156 - Revert "[Base] Use background mode for ThreadPriority::BACKGROUND threads (behind feature) (reland)."

The "revert" patch fixes headless functionality on windows.

References #846.
Fixes #3106.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants