Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Handle inspector crash (#70)
Browse files Browse the repository at this point in the history
* feat: dont crash

* feat: support fork

* Trigger CI

* fix: handle contextless events

* feat: readability

* fix: remove unneeded eventlistener
  • Loading branch information
soundofspace authored Oct 11, 2023
1 parent 6c16a9b commit 4d5e1f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/js-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
15 changes: 8 additions & 7 deletions agent/main/lib/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class Browser extends TypedEventEmitter<IBrowserEvents> 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);
Expand Down Expand Up @@ -380,18 +380,19 @@ export default class Browser extends TypedEventEmitter<IBrowserEvents> 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 });
Expand Down

0 comments on commit 4d5e1f5

Please sign in to comment.