-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(global-listeners): iterate all execution contexts #15054
Changes from all commits
d4fe038
84afe30
9b4c35d
3a9be89
078123a
ed67e34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,17 @@ class Driver { | |
rootSession: () => { | ||
return this.defaultSession; | ||
}, | ||
// For legacy driver, only bother supporting access to the default execution context. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a reasonable time to stop trying for parity wrt legacy driver. So...just giving the default EC here. |
||
mainFrameExecutionContexts: () => { | ||
// @ts-expect-error - undefined ids are OK for purposes of calling protocol commands like Runtime.evaluate. | ||
return [/** @type {LH.Crdp.Runtime.ExecutionContextDescription} */({ | ||
id: undefined, | ||
uniqueId: undefined, | ||
origin: '', | ||
name: '', | ||
auxData: {isDefault: true, type: 'default', frameId: ''}, | ||
})]; | ||
}, | ||
/** | ||
* Bind to *any* protocol event. | ||
* @param {'protocolevent'} event | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -9,6 +9,7 @@ import jestMock from 'jest-mock'; | |||
import * as api from '../../index.js'; | ||||
import {createTestState, getAuditsBreakdown} from './pptr-test-utils.js'; | ||||
import {LH_ROOT} from '../../../root.js'; | ||||
import {TargetManager} from '../../gather/driver/target-manager.js'; | ||||
|
||||
describe('Fraggle Rock API', function() { | ||||
// eslint-disable-next-line no-invalid-this | ||||
|
@@ -147,6 +148,7 @@ describe('Fraggle Rock API', function() { | |||
|
||||
// eslint-disable-next-line max-len | ||||
it('should know target type of network requests from frames created before timespan', async () => { | ||||
const spy = jestMock.spyOn(TargetManager.prototype, '_onExecutionContextCreated'); | ||||
state.server.baseDir = `${LH_ROOT}/cli/test/fixtures`; | ||||
const {page, serverBaseUrl} = state; | ||||
|
||||
|
@@ -192,6 +194,18 @@ Array [ | |||
}, | ||||
] | ||||
`); | ||||
|
||||
// Check that TargetManager is getting execution context created events even if connecting | ||||
// to the page after they already exist. | ||||
// There are two execution contexts, one for the main frame and one for the iframe of | ||||
// the same origin. | ||||
const contextCreatedMainFrameCalls = | ||||
spy.mock.calls.filter(call => call[0].context.origin === 'http://localhost:10200'); | ||||
// For some reason, puppeteer gives us two created events for every uniqueId, | ||||
// so using Set here to ignore that detail. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some poking around. I think it's because we
Presumably Regardless, de-duping on the |
||||
expect(new Set(contextCreatedMainFrameCalls.map(call => call[0].context.uniqueId)).size) | ||||
.toEqual(2); | ||||
spy.mockRestore(); | ||||
}); | ||||
}); | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ declare module Gatherer { | |
url: () => Promise<string>; | ||
targetManager: { | ||
rootSession(): FRProtocolSession; | ||
mainFrameExecutionContexts(): Array<Crdp.Runtime.ExecutionContextDescription>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although we only want to process main frames in global listeners, I don't want that to happen via a method called just |
||
on(event: 'protocolevent', callback: (payload: Protocol.RawEventMessage) => void): void | ||
off(event: 'protocolevent', callback: (payload: Protocol.RawEventMessage) => void): void | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this since we only listen on the root session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, just adding for later in case that ever changes. Could be easy to overlook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
er, wait no this is important now. It filters out a number of execution contexts for this simple page:
coming from the iframe. comment out the iframe, and only the first execution context is present
9 is the iframe in the main document, 11 is an inframe inside
a11y_tester.html
. not sure what 13 could be, perhaps an extenstion.