Skip to content

Commit

Permalink
fix(puppet): browser ids
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Aug 27, 2021
1 parent 64cf27c commit 2761689
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions puppet-chrome/lib/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ interface IBrowserEvents {
}
const { log } = Log(module);

let browserIdCounter = 0;

export class Browser extends TypedEventEmitter<IBrowserEvents> implements IPuppetBrowser {
public readonly browserContextsById = new Map<string, BrowserContext>();
public readonly devtoolsSession: DevtoolsSession;
public onDevtoolsAttached?: (session: DevtoolsSession) => Promise<any>;

public get id() {
return this.connection.rootSession.id;
}
public id: string;

public get name(): string {
return this.version.product.split('/').shift();
Expand All @@ -49,6 +49,7 @@ export class Browser extends TypedEventEmitter<IBrowserEvents> 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));
Expand Down
10 changes: 6 additions & 4 deletions puppet-chrome/lib/BrowserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ export class BrowserContext
}

initializePage(page: Page): Promise<any> {
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<Page> {
Expand Down
2 changes: 1 addition & 1 deletion puppet-chrome/lib/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class Page extends TypedEventEmitter<IPuppetPageEvents> 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),
Expand Down

0 comments on commit 2761689

Please sign in to comment.