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

frame.title() throws protocol error when used with framenavigated #827

Closed
ebidel opened this issue Sep 19, 2017 · 3 comments · Fixed by #1415
Closed

frame.title() throws protocol error when used with framenavigated #827

ebidel opened this issue Sep 19, 2017 · 3 comments · Fixed by #1415
Assignees
Labels

Comments

@ebidel
Copy link
Contributor

ebidel commented Sep 19, 2017

Repro:

const browser = await puppeteer.launch();
const page = await browser.newPage();

page.on('framenavigated', async frame => {
  console.log(await frame.title());
  browser.close();  
});

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

Produces:

Error: Protocol error (Runtime.evaluate): Cannot find context with specified id undefined
@aslushnikov aslushnikov self-assigned this Sep 25, 2017
@jose920405
Copy link

+1

@gajus
Copy link

gajus commented Nov 8, 2017

Might be related, #1325.

@schelkun
Copy link
Contributor

Look at Puppeteer and browser communication:

◀ RECV {"method":"Runtime.executionContextDestroyed","params":{"executionContextId":1}}
◀ RECV {"method":"Runtime.executionContextsCleared","params":{}}

◀ RECV {"method":"Page.frameNavigated","params":{"frame":{"id":"(18AA6B65BF4D232A98D4234ADE302876)","loaderId":"3902379.2","url":"https://example.com/","securityOrigin":"https://example.com","mimeType":"text/html"}}}

SEND ► {"id":15,"method":"Runtime.callFunctionOn","params":{"functionDeclaration":"() =>  document.title","executionContextId":1,"arguments":[],"returnByValue":false,"awaitPromise":true}}

◀ RECV {"method":"Runtime.executionContextCreated","params":{"context":{"id":2,"origin":"https://example.com","name":"","auxData":{"isDefault":true,"frameId":"(18AA6B65BF4D232A98D4234ADE302876)"}}}}

◀ RECV {"method":"Network.loadingFinished","params":{"requestId":"3902379.1","timestamp":1374155.700265,"encodedDataLength":1450}}
◀ RECV {"method":"Page.domContentEventFired","params":{"timestamp":1374155.704123}}
◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"(18AA6B65BF4D232A98D4234ADE302876)","loaderId":"3902379.2","name":"DOMContentLoaded","timestamp":1374155.704123}}
◀ RECV {"method":"Page.loadEventFired","params":{"timestamp":1374155.704757}}
◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"(18AA6B65BF4D232A98D4234ADE302876)","loaderId":"3902379.2","name":"load","timestamp":1374155.704757}}
◀ RECV {"method":"Page.frameStoppedLoading","params":{"frameId":"(18AA6B65BF4D232A98D4234ADE302876)"}

◀ RECV {"error":{"code":-32000,"message":"Cannot find context with specified id"},"id":15}

(node:3902334) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Protocol error (Runtime.callFunctionOn): Cannot find context with specified id undefined

executionContextCreated recieved after Page.frameNavigated, maybe this is the bug?

aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Nov 18, 2017
In Blink, frames don't necesserily have execution context all the time.
DevTools Protocol precisely reports this situation, which results in
Puppeteer's frame.executionContext() being null occasionally.

However, from puppeteer point of view every frame will have at least a
default executions context, sooner or later:
- frame's execution context might be created naturally to run frame's
  javascript
- if frame has no javascript, devtools protocol will issue execution
  context creation

This patch builds up on this assumption and introduces a PendingContext:
- Initially, frame is created with a PendingContext instead of a real
  context
- When frame clients request evaluations, PendingContext records
  evaluation requests
- When a real execution context is created, the PendingContext runs all
  the postponed evaluations in the real context

Fixes puppeteer#827, puppeteer#1325
aslushnikov added a commit that referenced this issue Nov 19, 2017
…#1415)

In Blink, frames don't necesserily have execution context all the time.
DevTools Protocol precisely reports this situation, which results in
Puppeteer's frame.executionContext() being null occasionally.

However, from puppeteer point of view every frame will have at least a
default executions context, sooner or later:

- frame's execution context might be created naturally to run frame's
  javascript
- if frame has no javascript, devtools protocol will issue execution
  context creation

This patch builds up on this assumption and makes frame.executionContext()
to be a promise.
As a result, all the evaluations await for the execution context to be created first.

Fixes #827, #1325

BREAKING CHANGE: this patch changes frame.executionContext() method to return a promise.
To migrate onto a new behavior, await the context first before using it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants