From 4d5e1f5bdbfd6ed55ba775ca9da941f22e8c2cb1 Mon Sep 17 00:00:00 2001 From: soundofspace <116737867+soundofspace@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:12:39 +0200 Subject: [PATCH] Handle inspector crash (#70) * feat: dont crash * feat: support fork * Trigger CI * fix: handle contextless events * feat: readability * fix: remove unneeded eventlistener --- .github/workflows/js-branch.yml | 2 +- agent/main/lib/Browser.ts | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/js-branch.yml b/.github/workflows/js-branch.yml index c216806f9..a3d790180 100644 --- a/.github/workflows/js-branch.yml +++ b/.github/workflows/js-branch.yml @@ -38,7 +38,7 @@ jobs: git init -b main git add -A git commit -m 'Auto-build Javascript files' - git push -f https://ulixee:${{ env.GH_TOKEN }}@github.com/ulixee/unblocked.git main:${{ github.ref_name }}-built-js + git push -f https://ulixee:${{ env.GH_TOKEN }}@github.com/${{github.repository}}.git main:${{ github.ref_name }}-built-js shell: bash env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/agent/main/lib/Browser.ts b/agent/main/lib/Browser.ts index 65005e16e..10f95305f 100755 --- a/agent/main/lib/Browser.ts +++ b/agent/main/lib/Browser.ts @@ -64,7 +64,7 @@ export default class Browser extends TypedEventEmitter implement private preferencesInterceptor?: DevtoolsPreferences; private browserContextCreationHooks: IBrowserContextHooks; - private connectOnlyToPageTargets: { [targetId: string]: IPageCreateOptions }; + private connectOnlyToPageTargets?: { [targetId: string]: IPageCreateOptions }; private get defaultBrowserContext(): BrowserContext { return this.browserContextsById.get(undefined); @@ -380,18 +380,19 @@ export default class Browser extends TypedEventEmitter implement private onAttachedToTarget(event: Protocol.Target.AttachedToTargetEvent): void { const { targetInfo, sessionId } = event; - assert(targetInfo.browserContextId, `targetInfo: ${JSON.stringify(targetInfo, null, 2)}`); - this.browserContextsById .get(targetInfo.browserContextId) ?.targetsById.set(targetInfo.targetId, targetInfo); const isDevtoolsPanel = targetInfo.url.startsWith('devtools://devtools'); + const isContextLess = !targetInfo.browserContextId; if ( - event.targetInfo.type === 'page' && - !isDevtoolsPanel && - this.connectOnlyToPageTargets && - !this.connectOnlyToPageTargets[targetInfo.targetId] + isContextLess || ( + event.targetInfo.type === 'page' && + !isDevtoolsPanel && + this.connectOnlyToPageTargets && + !this.connectOnlyToPageTargets[targetInfo.targetId] + ) ) { if (this.debugLog) { log.stats('Not connecting to target', { event, sessionId: null });