feat(exposeFunction): implement context-level expose on firefox (#1478)
This commit is contained in:
parent
23e5d80e06
commit
15ebe1c339
|
|
@ -9,7 +9,7 @@
|
|||
"main": "index.js",
|
||||
"playwright": {
|
||||
"chromium_revision": "751710",
|
||||
"firefox_revision": "1049",
|
||||
"firefox_revision": "1050",
|
||||
"webkit_revision": "1182"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ export class FFBrowserContext extends BrowserContextBase {
|
|||
throw new Error(`Function "${name}" has been already registered`);
|
||||
const binding = new PageBinding(name, playwrightFunction);
|
||||
this._pageBindings.set(name, binding);
|
||||
throw new Error('Not implemented');
|
||||
await this._browser._connection.send('Browser.addBinding', { browserContextId: this._browserContextId || undefined, name, script: binding.source });
|
||||
}
|
||||
|
||||
async route(url: types.URLMatch, handler: network.RouteHandler): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -266,9 +266,7 @@ export class FFPage implements PageDelegate {
|
|||
}
|
||||
|
||||
async exposeBinding(binding: PageBinding) {
|
||||
await this._session.send('Page.addBinding', {name: binding.name});
|
||||
await this._session.send('Page.addScriptToEvaluateOnNewDocument', {script: binding.source});
|
||||
await Promise.all(this._page.frames().map(frame => frame.evaluate(binding.source).catch(debugError)));
|
||||
await this._session.send('Page.addBinding', { name: binding.name, script: binding.source });
|
||||
}
|
||||
|
||||
didClose() {
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
|
|||
});
|
||||
|
||||
describe('BrowserContext.exposeFunction', () => {
|
||||
it.fail(FFOX)('should work', async({browser, server}) => {
|
||||
it('should work', async({browser, server}) => {
|
||||
const context = await browser.newContext();
|
||||
await context.exposeFunction('add', (a, b) => a + b);
|
||||
const page = await context.newPage();
|
||||
|
|
@ -337,7 +337,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
|
|||
expect(result).toEqual({ mul: 36, add: 13 });
|
||||
await context.close();
|
||||
});
|
||||
it.fail(FFOX)('should throw for duplicate registrations', async({browser, server}) => {
|
||||
it('should throw for duplicate registrations', async({browser, server}) => {
|
||||
const context = await browser.newContext();
|
||||
await context.exposeFunction('foo', () => {});
|
||||
await context.exposeFunction('bar', () => {});
|
||||
|
|
@ -351,7 +351,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
|
|||
expect(error.message).toBe('Function "baz" has been already registered in one of the pages');
|
||||
await context.close();
|
||||
});
|
||||
it.fail(FFOX)('should be callable from-inside addInitScript', async({browser, server}) => {
|
||||
it('should be callable from-inside addInitScript', async({browser, server}) => {
|
||||
const context = await browser.newContext();
|
||||
let args = [];
|
||||
await context.exposeFunction('woof', function(arg) {
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WE
|
|||
await context.close();
|
||||
expect(injected).toBe(123);
|
||||
});
|
||||
it.fail(FFOX)('should expose function from browser context', async function({browser, server}) {
|
||||
it('should expose function from browser context', async function({browser, server}) {
|
||||
const context = await browser.newContext();
|
||||
await context.exposeFunction('add', (a, b) => a + b);
|
||||
const page = await context.newPage();
|
||||
|
|
|
|||
Loading…
Reference in a new issue