Skip to content

Commit 15ebe1c

Browse files
authored
feat(exposeFunction): implement context-level expose on firefox (#1478)
1 parent 23e5d80 commit 15ebe1c

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"main": "index.js",
1010
"playwright": {
1111
"chromium_revision": "751710",
12-
"firefox_revision": "1049",
12+
"firefox_revision": "1050",
1313
"webkit_revision": "1182"
1414
},
1515
"scripts": {

src/firefox/ffBrowser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class FFBrowserContext extends BrowserContextBase {
288288
throw new Error(`Function "${name}" has been already registered`);
289289
const binding = new PageBinding(name, playwrightFunction);
290290
this._pageBindings.set(name, binding);
291-
throw new Error('Not implemented');
291+
await this._browser._connection.send('Browser.addBinding', { browserContextId: this._browserContextId || undefined, name, script: binding.source });
292292
}
293293

294294
async route(url: types.URLMatch, handler: network.RouteHandler): Promise<void> {

src/firefox/ffPage.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ export class FFPage implements PageDelegate {
266266
}
267267

268268
async exposeBinding(binding: PageBinding) {
269-
await this._session.send('Page.addBinding', {name: binding.name});
270-
await this._session.send('Page.addScriptToEvaluateOnNewDocument', {script: binding.source});
271-
await Promise.all(this._page.frames().map(frame => frame.evaluate(binding.source).catch(debugError)));
269+
await this._session.send('Page.addBinding', { name: binding.name, script: binding.source });
272270
}
273271

274272
didClose() {

test/browsercontext.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
326326
});
327327

328328
describe('BrowserContext.exposeFunction', () => {
329-
it.fail(FFOX)('should work', async({browser, server}) => {
329+
it('should work', async({browser, server}) => {
330330
const context = await browser.newContext();
331331
await context.exposeFunction('add', (a, b) => a + b);
332332
const page = await context.newPage();
@@ -337,7 +337,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
337337
expect(result).toEqual({ mul: 36, add: 13 });
338338
await context.close();
339339
});
340-
it.fail(FFOX)('should throw for duplicate registrations', async({browser, server}) => {
340+
it('should throw for duplicate registrations', async({browser, server}) => {
341341
const context = await browser.newContext();
342342
await context.exposeFunction('foo', () => {});
343343
await context.exposeFunction('bar', () => {});
@@ -351,7 +351,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
351351
expect(error.message).toBe('Function "baz" has been already registered in one of the pages');
352352
await context.close();
353353
});
354-
it.fail(FFOX)('should be callable from-inside addInitScript', async({browser, server}) => {
354+
it('should be callable from-inside addInitScript', async({browser, server}) => {
355355
const context = await browser.newContext();
356356
let args = [];
357357
await context.exposeFunction('woof', function(arg) {

test/popup.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WE
166166
await context.close();
167167
expect(injected).toBe(123);
168168
});
169-
it.fail(FFOX)('should expose function from browser context', async function({browser, server}) {
169+
it('should expose function from browser context', async function({browser, server}) {
170170
const context = await browser.newContext();
171171
await context.exposeFunction('add', (a, b) => a + b);
172172
const page = await context.newPage();

0 commit comments

Comments
 (0)