papersearch 0.4.9 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +50 -63
- package/README.md +50 -63
- package/assets/overview.en.png +0 -0
- package/assets/overview.png +0 -0
- package/assets/progress-capsule.en.png +0 -0
- package/assets/progress-capsule.png +0 -0
- package/carsi/README.md +5 -6
- package/carsi/paper_search_carsi/adapters/elsevier/__init__.py +1 -1
- package/carsi/paper_search_carsi/adapters/ieee/__init__.py +1 -1
- package/carsi/paper_search_carsi/adapters/jama/__init__.py +3 -1
- package/carsi/paper_search_carsi/adapters/karger/__init__.py +2 -1
- package/carsi/paper_search_carsi/adapters/lww/ovid.py +2 -2
- package/carsi/paper_search_carsi/adapters/oup/__init__.py +3 -4
- package/carsi/paper_search_carsi/adapters/world_scientific/__init__.py +5 -4
- package/carsi/paper_search_carsi/assets/capsule.html +114 -15
- package/carsi/paper_search_carsi/browser/backend.py +269 -233
- package/carsi/paper_search_carsi/browser/batch_session.py +42 -0
- package/carsi/paper_search_carsi/browser/challenge_interaction.py +28 -9
- package/carsi/paper_search_carsi/browser/cookies.py +8 -8
- package/carsi/paper_search_carsi/browser/driver.py +29 -0
- package/carsi/paper_search_carsi/browser/engine.py +17 -23
- package/carsi/paper_search_carsi/browser/foreground.py +21 -15
- package/carsi/paper_search_carsi/browser/login.py +12 -18
- package/carsi/paper_search_carsi/browser/preview.py +31 -12
- package/carsi/paper_search_carsi/browser/profiles.py +16 -23
- package/carsi/paper_search_carsi/browser/watchdog.py +61 -55
- package/carsi/paper_search_carsi/cli.py +22 -7
- package/carsi/paper_search_carsi/cold_start.py +65 -51
- package/carsi/paper_search_carsi/config.py +6 -4
- package/carsi/paper_search_carsi/engine/batch.py +9 -5
- package/carsi/paper_search_carsi/engine/batch_capture.py +56 -20
- package/carsi/paper_search_carsi/engine/batch_common.py +56 -16
- package/carsi/paper_search_carsi/engine/batch_institution.py +122 -13
- package/carsi/paper_search_carsi/engine/batch_login.py +30 -2
- package/carsi/paper_search_carsi/engine/batch_user.py +1 -1
- package/carsi/paper_search_carsi/engine/batch_waits.py +21 -7
- package/carsi/paper_search_carsi/engine/bridge.py +23 -13
- package/carsi/paper_search_carsi/engine/login_wait.py +1 -1
- package/carsi/paper_search_carsi/mcp_progress.py +13 -5
- package/carsi/paper_search_carsi/network.py +1 -1
- package/carsi/paper_search_carsi/progress_reporter.py +88 -7
- package/carsi/paper_search_carsi/progress_view.py +61 -0
- package/carsi/paper_search_carsi/server.py +47 -10
- package/carsi/paper_search_carsi/session_broker.py +1 -1
- package/carsi/pyproject.toml +7 -7
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js +6 -0
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.js +15 -5
- package/dist/capabilities/pdf-discovery/batch.js.map +1 -1
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts +22 -0
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/batchSummary.js +131 -0
- package/dist/capabilities/pdf-discovery/batchSummary.js.map +1 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.d.ts +1 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js +52 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.d.ts +8 -4
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +89 -30
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.d.ts +4 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.js +10 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.d.ts +2 -2
- package/dist/capabilities/pdf-discovery/carsi/index.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.js +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/types.d.ts +36 -0
- package/dist/capabilities/pdf-discovery/carsi/types.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/handler.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/handler.js +11 -6
- package/dist/capabilities/pdf-discovery/handler.js.map +1 -1
- package/dist/capabilities/pdf-discovery/types.d.ts +3 -0
- package/dist/capabilities/pdf-discovery/types.d.ts.map +1 -1
- package/dist/cli.js +13 -9
- package/dist/cli.js.map +1 -1
- package/dist/management/carsi/installer.d.ts +26 -14
- package/dist/management/carsi/installer.d.ts.map +1 -1
- package/dist/management/carsi/installer.js +113 -69
- package/dist/management/carsi/installer.js.map +1 -1
- package/dist/management/carsi/runtime.d.ts +12 -1
- package/dist/management/carsi/runtime.d.ts.map +1 -1
- package/dist/management/carsi/runtime.js +30 -1
- package/dist/management/carsi/runtime.js.map +1 -1
- package/package.json +1 -1
- package/skills/paper-search/SKILL.md +4 -4
- package/skills/paper-search/references/browser-download.md +3 -3
- package/skills/paper-search/references/carsi-setup.md +7 -6
- package/skills/paper-search/references/cli-contract.md +4 -4
- package/skills/paper-search/references/management-layer.md +2 -2
- package/carsi/paper_search_carsi/assets/quiet-browser/api.js +0 -142
- package/carsi/paper_search_carsi/assets/quiet-browser/manifest.json +0 -24
- package/carsi/paper_search_carsi/assets/quiet-browser/schema.json +0 -1
- package/carsi/paper_search_carsi/browser/background.py +0 -68
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
- 出版社网站拦截了当前网络(`access_blocked`,如 Cloudflare 拦截页)时这一篇结束;同一期刊 30 分钟内的其他文章直接跳过(`journal_blocked_earlier`),其他期刊照常继续。告诉用户可能是当前网络被网站防护拦截,也可能是下载过多被暂停:可换网络或稍后再试,后者请联系学校图书馆。
|
|
22
22
|
- 后端会先短暂等待自动验证,每次验证等待对可识别的 Turnstile 复选框最多尝试点击 3 次,两次至少间隔 3 秒;程序提示人工处理时,再提醒用户到下载浏览器接管,不因 `checking_access` 就要求用户操作。学校登录、二次验证和复杂验证码由用户完成;不索取账号、密码或验证码,agent 不另开浏览器代操作。
|
|
23
23
|
- 在专用人工登录页输入、选择或点击控件,或点击胶囊接管登录后,暂停剩余学校登录预算;输入间停顿不算离开,离开该人工步骤后恢复计时。无人操作仍按原限时结束。不要询问账号密码、监听系统输入或将用户暂时未输入视为离开。
|
|
24
|
-
-
|
|
24
|
+
- 学校登录提醒依赖当前可见的账号、密码、二次验证码、二维码或同意步骤;学校域名和空闲时间不作为人工操作证据。胶囊“验证提醒前最多等”仍保存到 `browser_stall_notify_after`(默认 30 秒,1–600);可见验证控件无法自动操作时,按该值与剩余预算一半的较早者交接。控件仍在加载、已勾选处理中或尚未出现时继续自动观察。未派发点击不消耗最多 3 次输入额度;失败原因见 `challenge_observation`。明确网站封禁和预算耗尽仍结束当前路径,不保证所有验证码自动通过。
|
|
25
25
|
- 通用 Human Verification 图片验证页会等待 Begin 之后的后续步骤。用户在专用验证页操作或通过胶囊接管后,人工阶段暂停剩余验证及文章等待预算;成功离开验证后继续自动流程。未操作时仍按原时限结束,外层任务资源限制不变。
|
|
26
26
|
- 阶段以本次调用的结构化通知为准(命令写在 stderr,stdout 只有最终 JSON);不凭等待时间猜阶段。
|
|
27
27
|
- PDF 在新标签页打开不等于已保存;以命令的最终结果为准,网页地址不是本地文件。
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
## 进度窗口和问题报告
|
|
31
31
|
|
|
32
32
|
- 进度窗口是屏幕角落的小胶囊(macOS 右上、Windows 右下):显示完成数/总数、正在下正文还是附录、出版社;需要用户登录或验证时变成琥珀色,背景与边缘轻柔呼吸并显示倒计时,开启系统通知时同时发一条通知;系统开启“减少动态效果”时只变色。鼠标指上去展开,看当前论文、步骤、成功/失败/剩余和下面的按钮;右上角“–”最小化到程序坞或任务栏。全部成功时结束 8 秒后自动关,有失败或终止时留着,等用户点 × 关闭。pywebview 或网页引擎用不了时自动换成旧版窗口,按钮相同。
|
|
33
|
-
-
|
|
33
|
+
- 下载用的 Google Chrome 窗口保持运行,但启动、跳转、开新标签及等待人工处理时不主动抢前台。需要操作时点击胶囊的“请登录学校”等提醒,可切到当前任务的下载浏览器。
|
|
34
34
|
- Mac 的系统通知使用 PaperSearch 名称与图标;通知点击共用胶囊的当前任务浏览器恢复入口。系统通知权限或专注模式可能限制横幅,胶囊提醒仍保留。无需另外安装通知工具,不替用户修改系统通知设置。
|
|
35
35
|
- 胶囊齿轮可修改默认下载文件夹(输入绝对路径或选择文件夹),与 `paper-search config set DEFAULT_DOWNLOAD_PATH "/完整路径/论文"` 共用配置。新任务自动采用它;显式 `savePath` / `--save-path` 优先,运行中批次不改目录。
|
|
36
36
|
- “终止”(旧版窗口里叫“终止任务”):确认后当前这一篇立即结束,整批停下,剩下的篇目记为 `batch_stopped`(未下载)。用户想停下整批时让他点这个,不要另外中止命令。
|
|
@@ -93,7 +93,7 @@ paper-search failures --format text
|
|
|
93
93
|
|
|
94
94
|
`pdf_identity_unverified` / `pdf_identity_mismatch`:不能报成功,`review.path` 只是待核查的文件。
|
|
95
95
|
|
|
96
|
-
##
|
|
96
|
+
## 导出失败记录
|
|
97
97
|
|
|
98
98
|
```bash
|
|
99
99
|
paper-search failures --export ./failure-report.zip
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
paper-search carsi status --format text
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
显示是否已装、安装目录、所用浏览器(Google Chrome 的路径和版本、驱动版本)、学校、PaperSearch 是否已启用它。Chrome 低于测试过的版本时会提示先更新 Chrome。
|
|
12
12
|
|
|
13
13
|
没有安装、而用户需要用学校权限下载时,先征得用户同意,再运行:
|
|
14
14
|
|
|
@@ -16,7 +16,8 @@ paper-search carsi status --format text
|
|
|
16
16
|
paper-search carsi install
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
-
|
|
19
|
+
- 需要本机已装 Google Chrome;没有时安装会停下并给出下载地址 https://www.google.com/chrome/,请用户装好 Chrome 后再运行同一命令。`--browser ego` 改用用户自己的 ego lite(仅 macOS)。
|
|
20
|
+
- 安装前会列出安装位置和下载量(约 0.5 GB,不另下载浏览器),用户确认后才开始。`--yes` 跳过确认,只在用户明确同意后使用。
|
|
20
21
|
- 用户不需要先装 Python;中途失败时,处理提示的问题后再运行同一命令,会从失败的那一步接着装。
|
|
21
22
|
- 装完会自动启用(`PAPER_SEARCH_CARSI_ENABLED=true`、`PAPER_SEARCH_CARSI_EXECUTABLE` 指向新装的后端)。原来配置了别的后端时,会先问用户是否替换。
|
|
22
23
|
- 安装时会问学校;`--skip-school` 跳过,之后再配置。
|
|
@@ -27,8 +28,8 @@ paper-search carsi install
|
|
|
27
28
|
|
|
28
29
|
## 更新与卸载
|
|
29
30
|
|
|
30
|
-
- PaperSearch 升级后,`status` 提示扩展落后时运行 `paper-search carsi update
|
|
31
|
-
- 卸载:`paper-search carsi uninstall`。先列出要删和保留的内容,用户确认后删除安装目录;PaperSearch
|
|
31
|
+
- PaperSearch 升级后,`status` 提示扩展落后时运行 `paper-search carsi update`:重装后端和依赖,检查 Chrome;学校配置、登录会话、Chrome 和 ego lite 不动。以前用 Camoufox 的安装会改用 Chrome,并写明旧 Camoufox 浏览器所在的目录,由用户决定是否手动删除。已是最新时不做任何事;`--force` 强制重装。
|
|
32
|
+
- 卸载:`paper-search carsi uninstall`。先列出要删和保留的内容,用户确认后删除安装目录;PaperSearch 配置指向这次安装的后端时,关闭机构下载并清除后端路径,指向别处时不改。学校配置和登录会话默认保留,会询问;`--yes` 时保留,除非另加 `--remove-data`。Google Chrome 和 ego lite 不受影响。
|
|
32
33
|
|
|
33
34
|
## 学校
|
|
34
35
|
|
|
@@ -51,14 +52,14 @@ paper-search-carsi setup --carsi --institution "学校名"
|
|
|
51
52
|
|
|
52
53
|
后端配置键 `browser_backend` 二选一:
|
|
53
54
|
|
|
54
|
-
- `camoufox
|
|
55
|
+
- `chrome`(默认):用户本机的 Google Chrome,由后端用单独的浏览器资料启动,不动用户日常 Chrome 的资料和标签页。第一次下载时用户在它的窗口里登录一次学校,之后保留。日常和批量下载用它。Chrome 装在别处时:`paper-search-carsi config set chrome_executable <Chrome 程序路径>`。旧值 `camoufox` 按 `chrome` 处理。
|
|
55
56
|
- `ego`:需要沿用用户 ego lite 里已有的登录时选用(Chromium 内核,用户和 agent 看的是同一个浏览器,仅 macOS)。用户须在 ego 打开 `chrome://inspect/#remote-debugging`,勾选一次 “Allow remote debugging for this browser instance”。每次连接(例如 ego 重启后)ego 会弹出一次“允许连接”,由用户确认;ego 窗口在后台时常被直接拒绝,下载会立即报错并写明原因,请用户把 ego 放到前台、点“允许”后重试。
|
|
56
57
|
|
|
57
58
|
查看或切换:
|
|
58
59
|
|
|
59
60
|
```bash
|
|
60
61
|
paper-search-carsi config get browser_backend
|
|
61
|
-
paper-search-carsi config set browser_backend
|
|
62
|
+
paper-search-carsi config set browser_backend chrome
|
|
62
63
|
```
|
|
63
64
|
|
|
64
65
|
两套浏览器资料互不影响,切换不会删除另一套。用户没有要求时不擅自切换;也可以用 `paper-search carsi install --browser ego` 切换安装。
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
- `paper-search metrics ...` 是 `journal-metrics` 的别名。
|
|
20
20
|
- `paper-search status [--validate] [--pretty]`
|
|
21
21
|
- `paper-search doctor [--validate] [--format text] [--pretty]`
|
|
22
|
-
- `paper-search failures [--run ID|--since YYYY-MM-DD|--runs N] [--doi DOI] [--export file.zip] [--all] [--format text] [--pretty]
|
|
23
|
-
- `paper-search update check [--format text] [--pretty]
|
|
24
|
-
- `paper-search carsi install [--browser
|
|
22
|
+
- `paper-search failures [--run ID|--since YYYY-MM-DD|--runs N] [--doi DOI] [--export file.zip] [--all] [--format text] [--pretty]`
|
|
23
|
+
- `paper-search update check [--format text] [--pretty]`(只检查,不安装)
|
|
24
|
+
- `paper-search carsi install [--browser chrome|ego] [--yes] [--force] [--skip-school] [--format text]`
|
|
25
25
|
- `paper-search carsi status [--format text] [--pretty]`
|
|
26
26
|
- `paper-search carsi update [--force] [--format text] [--pretty]`
|
|
27
|
-
- `paper-search carsi uninstall [--yes] [--remove-
|
|
27
|
+
- `paper-search carsi uninstall [--yes] [--remove-data] [--format text] [--pretty]`
|
|
28
28
|
- `paper-search smoke --mock [--pretty]`
|
|
29
29
|
- `paper-search smoke --live [--pretty]`
|
|
30
30
|
- `paper-search skills status [--targets CSV] [--pretty]`
|
|
@@ -125,7 +125,7 @@ paper-search carsi install
|
|
|
125
125
|
paper-search doctor --pretty
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
`install`
|
|
128
|
+
`install` 先检查本机有 Google Chrome,列出要下载的内容和位置,再准备它自己的 Python、安装后端,并启用它(`PAPER_SEARCH_CARSI_ENABLED=true`、`PAPER_SEARCH_CARSI_EXECUTABLE`)。PaperSearch 升级后,`status` 会提示何时运行 `paper-search carsi update`。用户在别处维护的后端用 `paper-search config set PAPER_SEARCH_CARSI_EXECUTABLE <路径>` 指定。学校、浏览器(Google Chrome 或 ego)和账号见 `carsi-setup.md`;账号密码只在用户自己的浏览器里输入,不进聊天、配置、命令参数或日志。`doctor` 显示 `available` 只证明后端接口能用,不代表已登录学校或对某篇有权限。日常下载仍用 `paper-search download`、`paper-search run download_with_fallback` 或 `download_batch`,见 `browser-download.md`。
|
|
129
129
|
|
|
130
130
|
## 配置检查
|
|
131
131
|
|
|
@@ -148,7 +148,7 @@ paper-search doctor --pretty
|
|
|
148
148
|
|
|
149
149
|
不要让用户把密钥贴到聊天里,不要把密钥写进 Skill、README、测试或日志。`doctor` 和 `config` 的输出会把已配置的密钥脱敏。
|
|
150
150
|
|
|
151
|
-
## CLI
|
|
151
|
+
## CLI 新版提醒
|
|
152
152
|
|
|
153
153
|
日常在线任务可异步检查 npm `papersearch` 的稳定新版,成功结果缓存 24 小时,失败或未完成请求退避 1 小时。发现新版后,每次日常调用提示一次当前/最新版本和匹配安装渠道的升级命令;提醒在 stderr,stdout JSON 和原任务结果不变。离线管理命令不联网,CI、help/version/config/setup/update 不自动提醒。
|
|
154
154
|
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/* Only loaded in PaperSearch's owned Camoufox process, never in the user's browser.
|
|
2
|
-
* Camoufox's Juggler restores/focuses a native window for every automated click.
|
|
3
|
-
* Suppress that focus while retaining its tab selection and trusted input path.
|
|
4
|
-
* Explicit Page.bringToFront and native user input retain normal activation.
|
|
5
|
-
*/
|
|
6
|
-
var { ExtensionCommon } = ChromeUtils.importESModule("resource://gre/modules/ExtensionCommon.sys.mjs");
|
|
7
|
-
var papersearchBackground = class extends ExtensionCommon.ExtensionAPI {
|
|
8
|
-
onStartup() {
|
|
9
|
-
if (!Services.prefs.getBoolPref("papersearch.background.enabled", false)) return;
|
|
10
|
-
this.start().catch(async error => {
|
|
11
|
-
console.error("PaperSearch background helper:", error);
|
|
12
|
-
await IOUtils.writeJSON(PathUtils.join(PathUtils.profileDir, "papersearch-background.json"),
|
|
13
|
-
{ready: false, session: Services.prefs.getStringPref("papersearch.background.session", ""),
|
|
14
|
-
error: String(error).slice(0, 300)});
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
onShutdown() { this.restore?.(); }
|
|
18
|
-
async start() {
|
|
19
|
-
const {PageTarget, TargetRegistry} = ChromeUtils.importESModule("chrome://juggler/content/TargetRegistry.js");
|
|
20
|
-
const {PageHandler} = ChromeUtils.importESModule("chrome://juggler/content/protocol/PageHandler.js");
|
|
21
|
-
const activate = PageTarget.prototype.activateAndRun;
|
|
22
|
-
const bringToFront = PageHandler.prototype["Page.bringToFront"];
|
|
23
|
-
if (typeof activate !== "function" || typeof bringToFront !== "function") {
|
|
24
|
-
throw new Error("Unsupported Camoufox activation API");
|
|
25
|
-
}
|
|
26
|
-
const newPage = TargetRegistry.prototype._newPageInternal;
|
|
27
|
-
if (typeof newPage !== "function") throw new Error("Unsupported Camoufox page API");
|
|
28
|
-
const {Helper} = ChromeUtils.importESModule("chrome://juggler/content/Helper.js");
|
|
29
|
-
const helper = new Helper();
|
|
30
|
-
TargetRegistry.prototype._newPageInternal = async function({browserContextId}) {
|
|
31
|
-
const win = Services.wm.getMostRecentWindow("navigator:browser");
|
|
32
|
-
if (!win?.gBrowser) return await newPage.call(this, {browserContextId});
|
|
33
|
-
const browserContext = this.browserContextForId(browserContextId);
|
|
34
|
-
const tab = win.gBrowser.addTab("about:blank", {
|
|
35
|
-
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
|
|
36
|
-
userContextId: browserContext.userContextId,
|
|
37
|
-
skipAnimation: true,
|
|
38
|
-
});
|
|
39
|
-
let target = this._browserToTarget.get(tab.linkedBrowser);
|
|
40
|
-
while (!target) {
|
|
41
|
-
await helper.awaitEvent(this, TargetRegistry.Events.TargetCreated);
|
|
42
|
-
target = this._browserToTarget.get(tab.linkedBrowser);
|
|
43
|
-
}
|
|
44
|
-
await target.activateAndRun();
|
|
45
|
-
if (browserContext.crossProcessCookie.settings.timezoneId && await target.hasFailedToOverrideTimezone()) {
|
|
46
|
-
throw new Error("Failed to override timezone");
|
|
47
|
-
}
|
|
48
|
-
return target.id();
|
|
49
|
-
};
|
|
50
|
-
const pending = new WeakMap();
|
|
51
|
-
PageTarget.prototype.activateAndRun = async function(...args) {
|
|
52
|
-
const win = this._window;
|
|
53
|
-
let state = pending.get(win);
|
|
54
|
-
if (!state) {
|
|
55
|
-
state = {focus: win.focus, depth: 0};
|
|
56
|
-
pending.set(win, state);
|
|
57
|
-
win.focus = () => {};
|
|
58
|
-
}
|
|
59
|
-
state.depth++;
|
|
60
|
-
try { return await activate.apply(this, args); }
|
|
61
|
-
finally {
|
|
62
|
-
if (--state.depth === 0) {
|
|
63
|
-
win.focus = state.focus;
|
|
64
|
-
pending.delete(win);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
PageHandler.prototype["Page.bringToFront"] = async function(...args) {
|
|
69
|
-
const win = this._pageTarget._window;
|
|
70
|
-
if (win.windowState === win.STATE_MINIMIZED) win.restore();
|
|
71
|
-
(pending.get(win)?.focus || win.focus).call(win);
|
|
72
|
-
return await bringToFront.apply(this, args);
|
|
73
|
-
};
|
|
74
|
-
if (Services.prefs.getBoolPref("papersearch.background.bootstrap", false) &&
|
|
75
|
-
!Services.wm.getMostRecentWindow("navigator:browser")) {
|
|
76
|
-
const {AppConstants} = ChromeUtils.importESModule("resource://gre/modules/AppConstants.sys.mjs");
|
|
77
|
-
const uri = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
|
78
|
-
uri.data = "about:blank";
|
|
79
|
-
const win = Services.ww.openWindow(null, AppConstants.BROWSER_CHROME_URL, "_blank",
|
|
80
|
-
"chrome,dialog=no,all", uri);
|
|
81
|
-
const focus = win.focus;
|
|
82
|
-
win.focus = () => {};
|
|
83
|
-
const {ctypes} = ChromeUtils.importESModule("resource://gre/modules/ctypes.sys.mjs");
|
|
84
|
-
const user = ctypes.open("user32.dll");
|
|
85
|
-
const getStyle = user.declare("GetWindowLongPtrW", ctypes.winapi_abi, ctypes.intptr_t,
|
|
86
|
-
ctypes.voidptr_t, ctypes.int);
|
|
87
|
-
const setStyle = user.declare("SetWindowLongPtrW", ctypes.winapi_abi, ctypes.intptr_t,
|
|
88
|
-
ctypes.voidptr_t, ctypes.int, ctypes.intptr_t);
|
|
89
|
-
const setPosition = user.declare("SetWindowPos", ctypes.winapi_abi, ctypes.int,
|
|
90
|
-
ctypes.voidptr_t, ctypes.voidptr_t, ctypes.int, ctypes.int, ctypes.int, ctypes.int, ctypes.uint32_t);
|
|
91
|
-
const setAlpha = user.declare("SetLayeredWindowAttributes", ctypes.winapi_abi, ctypes.int,
|
|
92
|
-
ctypes.voidptr_t, ctypes.uint32_t, ctypes.unsigned_char, ctypes.uint32_t);
|
|
93
|
-
const getAlpha = user.declare("GetLayeredWindowAttributes", ctypes.winapi_abi, ctypes.int,
|
|
94
|
-
ctypes.voidptr_t, ctypes.uint32_t.ptr, ctypes.unsigned_char.ptr, ctypes.uint32_t.ptr);
|
|
95
|
-
const native = win.docShell.treeOwner.QueryInterface(Ci.nsIBaseWindow);
|
|
96
|
-
const hwnd = ctypes.voidptr_t(ctypes.UInt64(native.nativeHandle));
|
|
97
|
-
const style = Number(getStyle(hwnd, -20).toString());
|
|
98
|
-
const color = ctypes.uint32_t(), alpha = ctypes.unsigned_char(), alphaFlags = ctypes.uint32_t();
|
|
99
|
-
if ((style & 0x00080000) && !getAlpha(hwnd, color.address(), alpha.address(), alphaFlags.address())) {
|
|
100
|
-
user.close();
|
|
101
|
-
throw new Error("Cannot preserve browser window opacity");
|
|
102
|
-
}
|
|
103
|
-
// NOACTIVATE alone still lets Gecko's first ShowWindow cover another
|
|
104
|
-
// app. Keep only the initial, not-yet-painted window transparent until
|
|
105
|
-
// it can be placed behind existing windows, then restore normal styles.
|
|
106
|
-
setStyle(hwnd, -20, style | 0x08080000); // WS_EX_NOACTIVATE | WS_EX_LAYERED
|
|
107
|
-
if (!setAlpha(hwnd, 0, 0, 2)) {
|
|
108
|
-
setStyle(hwnd, -20, style);
|
|
109
|
-
user.close();
|
|
110
|
-
throw new Error("Cannot prepare the browser's background display");
|
|
111
|
-
}
|
|
112
|
-
let observer, timer;
|
|
113
|
-
try {
|
|
114
|
-
await new Promise((resolve, reject) => {
|
|
115
|
-
timer = win.setTimeout(() => reject(new Error("Browser window initialization timed out")), 10000);
|
|
116
|
-
observer = subject => {
|
|
117
|
-
if (subject !== win) return;
|
|
118
|
-
resolve();
|
|
119
|
-
};
|
|
120
|
-
Services.obs.addObserver(observer, "browser-delayed-startup-finished");
|
|
121
|
-
});
|
|
122
|
-
} finally {
|
|
123
|
-
if (observer) Services.obs.removeObserver(observer, "browser-delayed-startup-finished");
|
|
124
|
-
win.clearTimeout(timer);
|
|
125
|
-
const placed = setPosition(hwnd, ctypes.voidptr_t(1), 0, 0, 0, 0, 0x0013); // HWND_BOTTOM; NOSIZE|NOMOVE|NOACTIVATE
|
|
126
|
-
const opacityRestored = !(style & 0x00080000) || setAlpha(hwnd, color.value, alpha.value, alphaFlags.value);
|
|
127
|
-
setStyle(hwnd, -20, style);
|
|
128
|
-
user.close();
|
|
129
|
-
win.focus = focus;
|
|
130
|
-
if (!placed) throw new Error("Cannot place the browser behind existing windows");
|
|
131
|
-
if (!opacityRestored) throw new Error("Cannot restore the browser window opacity");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
await IOUtils.writeJSON(PathUtils.join(PathUtils.profileDir, "papersearch-background.json"),
|
|
135
|
-
{ready: true, session: Services.prefs.getStringPref("papersearch.background.session", "")});
|
|
136
|
-
this.restore = () => {
|
|
137
|
-
TargetRegistry.prototype._newPageInternal = newPage;
|
|
138
|
-
PageTarget.prototype.activateAndRun = activate;
|
|
139
|
-
PageHandler.prototype["Page.bringToFront"] = bringToFront;
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"manifest_version": 2,
|
|
3
|
-
"name": "PaperSearch background browser",
|
|
4
|
-
"version": "1.0",
|
|
5
|
-
"browser_specific_settings": {
|
|
6
|
-
"gecko": {
|
|
7
|
-
"id": "background@papersearch.local"
|
|
8
|
-
}
|
|
9
|
-
},
|
|
10
|
-
"experiment_apis": {
|
|
11
|
-
"papersearchBackground": {
|
|
12
|
-
"schema": "schema.json",
|
|
13
|
-
"parent": {
|
|
14
|
-
"scopes": [
|
|
15
|
-
"addon_parent"
|
|
16
|
-
],
|
|
17
|
-
"events": [
|
|
18
|
-
"startup"
|
|
19
|
-
],
|
|
20
|
-
"script": "api.js"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[{"namespace": "papersearchBackground"}]
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"""The owned Camoufox's bundled background helper; no native input or global hooks.
|
|
2
|
-
|
|
3
|
-
The helper is an internal Firefox experiment because window activation belongs
|
|
4
|
-
in browser chrome, outside web pages. It has no network/content permissions and
|
|
5
|
-
is not installed in a user's normal browser. Camoufox's version is pinned.
|
|
6
|
-
"""
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
import json
|
|
10
|
-
import hashlib
|
|
11
|
-
import io
|
|
12
|
-
import time
|
|
13
|
-
import zipfile
|
|
14
|
-
from pathlib import Path
|
|
15
|
-
from typing import Any
|
|
16
|
-
|
|
17
|
-
ADDON_ID = "background@papersearch.local"
|
|
18
|
-
ADDON_DIR = Path(__file__).resolve().parents[1] / "assets" / "quiet-browser"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def install_startup_helper(profile: Path) -> None:
|
|
22
|
-
"""Load before Windows creates its first window, inside the owned profile only."""
|
|
23
|
-
files = {p.name: p.read_bytes() for p in sorted(ADDON_DIR.iterdir()) if p.is_file()}
|
|
24
|
-
version = int.from_bytes(hashlib.sha256(b"".join(files.values())).digest()[:3], "big")
|
|
25
|
-
manifest = json.loads(files["manifest.json"])
|
|
26
|
-
manifest["version"] = f"1.0.{version}"
|
|
27
|
-
files["manifest.json"] = json.dumps(manifest).encode()
|
|
28
|
-
data = io.BytesIO()
|
|
29
|
-
with zipfile.ZipFile(data, "w", zipfile.ZIP_DEFLATED) as archive:
|
|
30
|
-
for name, content in files.items():
|
|
31
|
-
archive.writestr(zipfile.ZipInfo(name), content)
|
|
32
|
-
target = profile / "extensions" / (ADDON_ID + ".xpi")
|
|
33
|
-
content = data.getvalue()
|
|
34
|
-
if target.is_file() and target.read_bytes() == content:
|
|
35
|
-
return
|
|
36
|
-
target.parent.mkdir(parents=True, exist_ok=True)
|
|
37
|
-
temporary = target.with_suffix(".tmp")
|
|
38
|
-
temporary.write_bytes(content)
|
|
39
|
-
temporary.replace(target)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def options(opts: dict[str, Any]) -> None:
|
|
43
|
-
"""Configure only this launch; the shared installed browser is never patched."""
|
|
44
|
-
addons = list(opts.get("addons") or [])
|
|
45
|
-
if str(ADDON_DIR) not in addons:
|
|
46
|
-
addons.append(str(ADDON_DIR))
|
|
47
|
-
opts["addons"] = addons
|
|
48
|
-
prefs = opts["firefox_user_prefs"]
|
|
49
|
-
prefs.update({"extensions.experiments.enabled": True,
|
|
50
|
-
"layout.throttled_frame_rate": 60})
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def ready(profile: Path, session: str) -> None:
|
|
54
|
-
"""Verify before visiting any site; never claim quiet mode if the helper failed."""
|
|
55
|
-
path = profile / "papersearch-background.json"
|
|
56
|
-
deadline = time.monotonic() + 10
|
|
57
|
-
while time.monotonic() < deadline:
|
|
58
|
-
try:
|
|
59
|
-
if path.stat().st_size <= 4096:
|
|
60
|
-
result = json.loads(path.read_text(encoding="utf-8"))
|
|
61
|
-
if isinstance(result, dict) and result.get("session") == session:
|
|
62
|
-
if result.get("ready") is True:
|
|
63
|
-
return
|
|
64
|
-
raise RuntimeError("Camoufox background helper initialization failed")
|
|
65
|
-
except (OSError, ValueError):
|
|
66
|
-
pass # not written yet, or the atomic write is still being replaced
|
|
67
|
-
time.sleep(.05)
|
|
68
|
-
raise RuntimeError("Camoufox background helper did not initialize within 10 seconds")
|