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",
|
"main": "index.js",
|
||||||
"playwright": {
|
"playwright": {
|
||||||
"chromium_revision": "751710",
|
"chromium_revision": "751710",
|
||||||
"firefox_revision": "1049",
|
"firefox_revision": "1050",
|
||||||
"webkit_revision": "1182"
|
"webkit_revision": "1182"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ export class FFBrowserContext extends BrowserContextBase {
|
||||||
throw new Error(`Function "${name}" has been already registered`);
|
throw new Error(`Function "${name}" has been already registered`);
|
||||||
const binding = new PageBinding(name, playwrightFunction);
|
const binding = new PageBinding(name, playwrightFunction);
|
||||||
this._pageBindings.set(name, binding);
|
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> {
|
async route(url: types.URLMatch, handler: network.RouteHandler): Promise<void> {
|
||||||
|
|
|
||||||
|
|
@ -266,9 +266,7 @@ export class FFPage implements PageDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exposeBinding(binding: PageBinding) {
|
async exposeBinding(binding: PageBinding) {
|
||||||
await this._session.send('Page.addBinding', {name: binding.name});
|
await this._session.send('Page.addBinding', { name: binding.name, script: binding.source });
|
||||||
await this._session.send('Page.addScriptToEvaluateOnNewDocument', {script: binding.source});
|
|
||||||
await Promise.all(this._page.frames().map(frame => frame.evaluate(binding.source).catch(debugError)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
didClose() {
|
didClose() {
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserContext.exposeFunction', () => {
|
describe('BrowserContext.exposeFunction', () => {
|
||||||
it.fail(FFOX)('should work', async({browser, server}) => {
|
it('should work', async({browser, server}) => {
|
||||||
const context = await browser.newContext();
|
const context = await browser.newContext();
|
||||||
await context.exposeFunction('add', (a, b) => a + b);
|
await context.exposeFunction('add', (a, b) => a + b);
|
||||||
const page = await context.newPage();
|
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 });
|
expect(result).toEqual({ mul: 36, add: 13 });
|
||||||
await context.close();
|
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();
|
const context = await browser.newContext();
|
||||||
await context.exposeFunction('foo', () => {});
|
await context.exposeFunction('foo', () => {});
|
||||||
await context.exposeFunction('bar', () => {});
|
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');
|
expect(error.message).toBe('Function "baz" has been already registered in one of the pages');
|
||||||
await context.close();
|
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();
|
const context = await browser.newContext();
|
||||||
let args = [];
|
let args = [];
|
||||||
await context.exposeFunction('woof', function(arg) {
|
await context.exposeFunction('woof', function(arg) {
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WE
|
||||||
await context.close();
|
await context.close();
|
||||||
expect(injected).toBe(123);
|
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();
|
const context = await browser.newContext();
|
||||||
await context.exposeFunction('add', (a, b) => a + b);
|
await context.exposeFunction('add', (a, b) => a + b);
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue