Skip to content

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

fix(crawler): preserve proxy auth for external CDP contexts (#3231)

Mohamed Bassem4d3647994243
diff --git a/patches/[email protected] b/patches/[email protected]
index 2f587cec..bc5c91b4 100644
--- a/patches/[email protected]
+++ b/patches/[email protected]
@@ -1,8 +1,18 @@
diff --git a/lib/server/chromium/crBrowser.js b/lib/server/chromium/crBrowser.js
-index 104789ba12c6d547e056dfe468fa9f04bbcc638c..f56187925d980af6bacaf59a019d44a1cb498c80 100644
+index 104789ba12c6d547e056dfe468fa9f04bbcc638c..5f348b33ca323e3f44da8b3bf3e4db2357e47e00 100644
--- a/lib/server/chromium/crBrowser.js
+++ b/lib/server/chromium/crBrowser.js
-@@ -147,6 +147,15 @@ class CRBrowser extends import_browser.Browser {
+@@ -90,6 +90,9 @@ class CRBrowser extends import_browser.Browser {
+ return browser;
+ }
+ browser._defaultContext = new CRBrowserContext(browser, void 0, options.persistent);
++ // Karakeep patch: remember Chrome's real default browser context so that
++ // targets in contexts created by other CDP clients aren't adopted below.
++ browser._defaultBrowserContextId = (await session.send("Target.getBrowserContexts").catch(() => ({}))).defaultBrowserContextId;
+ await Promise.all([
+ session.send("Target.setAutoAttach", { autoAttach: true, waitForDebuggerOnStart: true, flatten: true }).then(async () => {
+ await session.send("Target.getTargetInfo");
+@@ -147,9 +150,29 @@ class CRBrowser extends import_browser.Browser {
if (targetInfo.type === "browser")
return;
const session = this._session.createChildSession(sessionId);
@@ -18,3 +28,17 @@ index 104789ba12c6d547e056dfe468fa9f04bbcc638c..f56187925d980af6bacaf59a019d44a1
(0, import_assert.assert)(targetInfo.browserContextId, "targetInfo: " + JSON.stringify(targetInfo, null, 2));
let context = this._contexts.get(targetInfo.browserContextId) || null;
if (!context) {
++ if (this._defaultBrowserContextId && targetInfo.browserContextId !== this._defaultBrowserContextId) {
++ // Karakeep patch: the target belongs to a browser context another CDP
++ // client created. Adopting it as a default-context page would enable
++ // Fetch with handleAuthRequests on it (patchright always intercepts),
++ // and Chrome hands the target's proxy auth challenges to the first
++ // client that did so: we'd answer them without credentials and break
++ // the owner's proxy authentication. Detaching resumes the target.
++ session.detach().catch(() => {
++ });
++ return;
++ }
+ context = this._defaultContext;
+ }
+ if (targetInfo.type === "other" && targetInfo.url.startsWith("devtools://devtools") && this._devtools) {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2e36bfc0..0e87aa7f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -21,7 +21,7 @@ overrides:
patchedDependencies:
[email protected]: 0de91114675edaf8158061b65f08995617cd872a813892f81e28394ded741a77
[email protected]: 0d82bc4e13dd196d0d74ab0507c5d042d1ca0df6403534afd76a8e18410436c6
- [email protected]: bad8f4246d462dedf01a4188e8d958032e1d8f1fcf243b33b1ecafe7ca41a1bd
+ [email protected]: e9c5d33d907bd9189082dcc2d58060bbcbd1ec3d633715b0762970b0d8898f3a
[email protected]: 7d74c7fbd33e9f3f3f8a8ba47a013acfc098948e39c7faab1232e6edca358ac1
[email protected]: d7b79c3ae412d8e700a8c176df42ee89112c9bdc91d2aad0ebb7d5b011b49993
[email protected]: 725863c0591d89ca053226c49fe7bc321f320391ec5f78b6c2e8e41ab1868805
@@ -31080,11 +31080,11 @@ snapshots:
no-case: 3.0.4
tslib: 2.8.1
- [email protected](patch_hash=bad8f4246d462dedf01a4188e8d958032e1d8f1fcf243b33b1ecafe7ca41a1bd): {}
+ [email protected](patch_hash=e9c5d33d907bd9189082dcc2d58060bbcbd1ec3d633715b0762970b0d8898f3a): {}
dependencies:
- patchright-core: 1.59.4(patch_hash=bad8f4246d462dedf01a4188e8d958032e1d8f1fcf243b33b1ecafe7ca41a1bd)
+ patchright-core: 1.59.4(patch_hash=e9c5d33d907bd9189082dcc2d58060bbcbd1ec3d633715b0762970b0d8898f3a)
optionalDependencies:
fsevents: 2.3.2