Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix(workers): don't crash connectOverCDP on context-less service workers (#3190)

Mohamed Bassemb783cf6d155d
diff --git a/patches/[email protected] b/patches/[email protected]
new file mode 100644
index 00000000..2f587cec
--- /dev/null
+++ b/patches/[email protected]
@@ -0,0 +1,20 @@
+diff --git a/lib/server/chromium/crBrowser.js b/lib/server/chromium/crBrowser.js
+index 104789ba12c6d547e056dfe468fa9f04bbcc638c..f56187925d980af6bacaf59a019d44a1cb498c80 100644
+--- a/lib/server/chromium/crBrowser.js
++++ b/lib/server/chromium/crBrowser.js
+@@ -147,6 +147,15 @@ class CRBrowser extends import_browser.Browser {
+ if (targetInfo.type === "browser")
+ return;
+ const session = this._session.createChildSession(sessionId);
++ if (targetInfo.type === "service_worker" && !targetInfo.browserContextId) {
++ // Karakeep patch: Chrome can report an already running service worker
++ // without a browserContextId (e.g. one whose context is gone). Detaching
++ // resumes it if it is paused and releases the session instead of failing
++ // the assertion below, which crashes the process.
++ session.detach().catch(() => {
++ });
++ return;
++ }
+ (0, import_assert.assert)(targetInfo.browserContextId, "targetInfo: " + JSON.stringify(targetInfo, null, 2));
+ let context = this._contexts.get(targetInfo.browserContextId) || null;
+ if (!context) {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fc627843..3f99ae08 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -21,6 +21,7 @@ overrides:
patchedDependencies:
[email protected]: 0de91114675edaf8158061b65f08995617cd872a813892f81e28394ded741a77
[email protected]: 0d82bc4e13dd196d0d74ab0507c5d042d1ca0df6403534afd76a8e18410436c6
+ [email protected]: bad8f4246d462dedf01a4188e8d958032e1d8f1fcf243b33b1ecafe7ca41a1bd
[email protected]: 7d74c7fbd33e9f3f3f8a8ba47a013acfc098948e39c7faab1232e6edca358ac1
[email protected]: d7b79c3ae412d8e700a8c176df42ee89112c9bdc91d2aad0ebb7d5b011b49993
[email protected]: 725863c0591d89ca053226c49fe7bc321f320391ec5f78b6c2e8e41ab1868805
@@ -31090,11 +31091,11 @@ snapshots:
no-case: 3.0.4
tslib: 2.8.1
+ [email protected](patch_hash=bad8f4246d462dedf01a4188e8d958032e1d8f1fcf243b33b1ecafe7ca41a1bd): {}
dependencies:
- patchright-core: 1.59.4
+ patchright-core: 1.59.4(patch_hash=bad8f4246d462dedf01a4188e8d958032e1d8f1fcf243b33b1ecafe7ca41a1bd)
optionalDependencies:
fsevents: 2.3.2
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 1124afa3..cc3f6a0c 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -33,6 +33,9 @@ patchedDependencies:
# Android: don't drop shares that arrive while the app is being recreated after
# process death, and don't replay the task's launch share on reopen (#513).
+ # Detach service worker targets that Chrome reports without a browserContextId
+ # instead of failing an assertion that crashes connectOverCDP().
# Docker builds can prune packages that use one of the root patches.
allowUnusedPatches: true