From 2761689507978ad3a47cc389bf8522a86c3e4e3d Mon Sep 17 00:00:00 2001 From: blakebyrnes Date: Fri, 27 Aug 2021 17:01:07 -0400 Subject: [PATCH] fix(puppet): browser ids --- puppet-chrome/lib/Browser.ts | 7 ++++--- puppet-chrome/lib/BrowserContext.ts | 10 ++++++---- puppet-chrome/lib/Page.ts | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/puppet-chrome/lib/Browser.ts b/puppet-chrome/lib/Browser.ts index d1dacee49..f26e26dbe 100755 --- a/puppet-chrome/lib/Browser.ts +++ b/puppet-chrome/lib/Browser.ts @@ -17,14 +17,14 @@ interface IBrowserEvents { } const { log } = Log(module); +let browserIdCounter = 0; + export class Browser extends TypedEventEmitter implements IPuppetBrowser { public readonly browserContextsById = new Map(); public readonly devtoolsSession: DevtoolsSession; public onDevtoolsAttached?: (session: DevtoolsSession) => Promise; - public get id() { - return this.connection.rootSession.id; - } + public id: string; public get name(): string { return this.version.product.split('/').shift(); @@ -49,6 +49,7 @@ export class Browser extends TypedEventEmitter implements IPuppe this.connection = connection; this.devtoolsSession = connection.rootSession; this.closeCallback = closeCallback; + this.id = String((browserIdCounter += 1)); this.connection.on('disconnected', this.emit.bind(this, 'disconnected')); this.devtoolsSession.on('Target.attachedToTarget', this.onAttachedToTarget.bind(this)); diff --git a/puppet-chrome/lib/BrowserContext.ts b/puppet-chrome/lib/BrowserContext.ts index 46a1100bc..3415e8891 100644 --- a/puppet-chrome/lib/BrowserContext.ts +++ b/puppet-chrome/lib/BrowserContext.ts @@ -123,11 +123,13 @@ export class BrowserContext } initializePage(page: Page): Promise { - if (this.pageOptionsByTargetId.get(page.targetId)?.runPageScripts === false) return; + if (this.pageOptionsByTargetId.get(page.targetId)?.runPageScripts === false) + return Promise.resolve(); - const promises = [this.defaultPageInitializationFn(page).catch(err => err)]; - promises.push(this.plugins.onNewPuppetPage(page).catch(err => err)); - return Promise.all(promises); + return Promise.all([ + this.defaultPageInitializationFn(page), + this.plugins.onNewPuppetPage(page), + ]); } async onPageAttached(devtoolsSession: DevtoolsSession, targetInfo: TargetInfo): Promise { diff --git a/puppet-chrome/lib/Page.ts b/puppet-chrome/lib/Page.ts index 94dd83e4a..fee3a00ae 100755 --- a/puppet-chrome/lib/Page.ts +++ b/puppet-chrome/lib/Page.ts @@ -361,7 +361,7 @@ export class Page extends TypedEventEmitter implements IPuppe flatten: true, }) .catch(err => err), - this.browserContext.initializePage(this), + this.browserContext.initializePage(this).catch(err => err), this.devtoolsSession .send('Page.setInterceptFileChooserDialog', { enabled: true }) .catch(err => err),