fix(chromium): install binding function during initialization (#1320)

This commit is contained in:
Dmitry Gozman 2020-03-10 16:19:01 -07:00 committed by GitHub
parent 65d10a5d5d
commit 3dd49459bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -92,11 +92,16 @@ export class CRPage implements PageDelegate {
helper.addEventListener(this._client, 'Target.attachedToTarget', event => this._onAttachedToTarget(event)),
helper.addEventListener(this._client, 'Target.detachedFromTarget', event => this._onDetachedFromTarget(event)),
];
this._page.frames().map(frame => this._client.send('Page.createIsolatedWorld', {
frameId: frame._id,
grantUniveralAccess: true,
worldName: UTILITY_WORLD_NAME,
}).catch(debugError)); // frames might be removed before we send this.
for (const frame of this._page.frames()) {
// Note: frames might be removed before we send these.
this._client.send('Page.createIsolatedWorld', {
frameId: frame._id,
grantUniveralAccess: true,
worldName: UTILITY_WORLD_NAME,
}).catch(debugError);
for (const binding of this._browserContext._pageBindings.values())
frame.evaluate(binding.source).catch(debugError);
}
}),
this._client.send('Log.enable', {}),
this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }),

View File

@ -612,6 +612,8 @@ export class PageBinding {
function addPageBinding(bindingName: string) {
const binding = (window as any)[bindingName];
if (binding.__installed)
return;
(window as any)[bindingName] = (...args: any[]) => {
const me = (window as any)[bindingName];
let callbacks = me['callbacks'];
@ -625,4 +627,5 @@ function addPageBinding(bindingName: string) {
binding(JSON.stringify({name: bindingName, seq, args}));
return promise;
};
(window as any)[bindingName].__installed = true;
}

View File

@ -326,7 +326,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
});
describe('BrowserContext.exposeFunction', () => {
it.fail(CHROMIUM || FFOX)('should work', async({browser, server}) => {
it.fail(FFOX)('should work', async({browser, server}) => {
const context = await browser.newContext();
await context.exposeFunction('add', (a, b) => a + b);
const page = await context.newPage();