feat(firefox): support target.opener() and page.on('popup') (#3966)
This commit is contained in:
parent
0cf6ab68e7
commit
cfefd611b8
@ -158,10 +158,18 @@ class Browser extends EventEmitter {
|
|||||||
return Array.from(this._pageTargets.values());
|
return Array.from(this._pageTargets.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTabOpened({pageId, url, browserContextId}) {
|
async _onTabOpened({pageId, url, browserContextId, openerId}) {
|
||||||
const context = browserContextId ? this._contexts.get(browserContextId) : this._defaultContext;
|
const context = browserContextId ? this._contexts.get(browserContextId) : this._defaultContext;
|
||||||
const target = new Target(this._connection, this, context, pageId, url);
|
const opener = openerId ? this._pageTargets.get(openerId) : null;
|
||||||
|
const target = new Target(this._connection, this, context, pageId, url, opener);
|
||||||
this._pageTargets.set(pageId, target);
|
this._pageTargets.set(pageId, target);
|
||||||
|
if (opener && opener._pagePromise) {
|
||||||
|
const openerPage = await opener._pagePromise;
|
||||||
|
if (openerPage.listenerCount(Events.Page.Popup)) {
|
||||||
|
const popupPage = await target.page();
|
||||||
|
openerPage.emit(Events.Page.Popup, popupPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.emit(Events.Browser.TargetCreated, target);
|
this.emit(Events.Browser.TargetCreated, target);
|
||||||
context.emit(Events.BrowserContext.TargetCreated, target);
|
context.emit(Events.BrowserContext.TargetCreated, target);
|
||||||
}
|
}
|
||||||
@ -194,8 +202,9 @@ class Target {
|
|||||||
* @param {!BrowserContext} context
|
* @param {!BrowserContext} context
|
||||||
* @param {string} pageId
|
* @param {string} pageId
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
|
* @param {?Target} opener
|
||||||
*/
|
*/
|
||||||
constructor(connection, browser, context, pageId, url) {
|
constructor(connection, browser, context, pageId, url, opener) {
|
||||||
this._browser = browser;
|
this._browser = browser;
|
||||||
this._context = context;
|
this._context = context;
|
||||||
this._connection = connection;
|
this._connection = connection;
|
||||||
@ -203,6 +212,14 @@ class Target {
|
|||||||
/** @type {?Promise<!Page>} */
|
/** @type {?Promise<!Page>} */
|
||||||
this._pagePromise = null;
|
this._pagePromise = null;
|
||||||
this._url = url;
|
this._url = url;
|
||||||
|
this._opener = opener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {?Target}
|
||||||
|
*/
|
||||||
|
opener() {
|
||||||
|
return this._opener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,6 +9,7 @@ const Events = {
|
|||||||
FrameNavigated: 'framenavigated',
|
FrameNavigated: 'framenavigated',
|
||||||
Load: 'load',
|
Load: 'load',
|
||||||
PageError: 'pageerror',
|
PageError: 'pageerror',
|
||||||
|
Popup: 'popup',
|
||||||
},
|
},
|
||||||
Browser: {
|
Browser: {
|
||||||
TargetCreated: 'targetcreated',
|
TargetCreated: 'targetcreated',
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"node": ">=8.9.4"
|
"node": ">=8.9.4"
|
||||||
},
|
},
|
||||||
"puppeteer": {
|
"puppeteer": {
|
||||||
"firefox_revision": "ed8e119ec1279c3db3638e90e910edb3816e0280"
|
"firefox_revision": "9702d3d2dd86550e385fadec66eb28a5ff2b1322"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node install.js",
|
"install": "node install.js",
|
||||||
|
@ -102,7 +102,7 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe_fails_ffox('Page.Events.Popup', function() {
|
describe('Page.Events.Popup', function() {
|
||||||
it('should work', async({page}) => {
|
it('should work', async({page}) => {
|
||||||
const [popup] = await Promise.all([
|
const [popup] = await Promise.all([
|
||||||
new Promise(x => page.once('popup', x)),
|
new Promise(x => page.once('popup', x)),
|
||||||
|
@ -132,7 +132,7 @@ module.exports.addTests = function({testRunner, expect, puppeteer, Errors}) {
|
|||||||
// Cleanup.
|
// Cleanup.
|
||||||
await newPage.close();
|
await newPage.close();
|
||||||
});
|
});
|
||||||
it_fails_ffox('should have an opener', async({page, server, context}) => {
|
it('should have an opener', async({page, server, context}) => {
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
const [createdTarget] = await Promise.all([
|
const [createdTarget] = await Promise.all([
|
||||||
new Promise(fulfill => context.once('targetcreated', target => fulfill(target))),
|
new Promise(fulfill => context.once('targetcreated', target => fulfill(target))),
|
||||||
|
Loading…
Reference in New Issue
Block a user