Skip to content

Commit

Permalink
feat(exposeFunction): implement context-level expose on firefox (#1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Mar 23, 2020
1 parent 23e5d80 commit 15ebe1c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"main": "index.js",
"playwright": {
"chromium_revision": "751710",
"firefox_revision": "1049",
"firefox_revision": "1050",
"webkit_revision": "1182"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/firefox/ffBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
4 changes: 1 addition & 3 deletions src/firefox/ffPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions test/browsercontext.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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', () => {});
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/popup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 15ebe1c

Please sign in to comment.