@dickpy/dsh-oil-slide 0.0.0-stage → 0.2.8
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/LICENSE +21 -0
- package/README.md +90 -2
- package/bundled-assets/brand/empty-deck-cobalt.webp +0 -0
- package/bundled-assets/brand/oil-slide-mark-512.png +0 -0
- package/bundled-assets/skill/LICENSE +21 -0
- package/bundled-assets/skill/README.md +61 -0
- package/bundled-assets/skill/SKILL.md +185 -0
- package/bundled-assets/skill/references/art-directions.md +99 -0
- package/bundled-assets/skill/references/brand-and-canvas.md +72 -0
- package/bundled-assets/skill/references/design-baseline.txt +1 -0
- package/bundled-assets/skill/references/prompt-compiler.md +99 -0
- package/bundled-assets/skill/references/restore-and-pptx.md +178 -0
- package/bundled-assets/skill/references/staged-pptx.md +71 -0
- package/bundled-assets/skill/scripts/_runtime_utils.py +351 -0
- package/bundled-assets/skill/scripts/asset_sheet.py +528 -0
- package/bundled-assets/skill/scripts/brand_ref.py +776 -0
- package/bundled-assets/skill/scripts/crop_asset.py +1709 -0
- package/bundled-assets/skill/scripts/deck_shell.py +2322 -0
- package/bundled-assets/skill/scripts/export_images.py +280 -0
- package/bundled-assets/skill/scripts/extract_pptx.py +360 -0
- package/bundled-assets/skill/scripts/extract_slide_dom.js +1640 -0
- package/bundled-assets/skill/scripts/html_to_pptx.py +4042 -0
- package/bundled-assets/skill/scripts/measure_slide_layout.py +952 -0
- package/bundled-assets/skill/scripts/oiloil-connect.mjs +1493 -0
- package/bundled-assets/skill/scripts/oiloil-image.mjs +492 -0
- package/bundled-assets/skill/scripts/prepare_plate.py +412 -0
- package/bundled-assets/skill/scripts/render_gradient.py +258 -0
- package/bundled-assets/skill/scripts/slide_brand.py +111 -0
- package/bundled-assets/skill/scripts/slide_incremental.py +122 -0
- package/bundled-assets/skill/scripts/slide_workflow.py +711 -0
- package/bundled-assets/skill/scripts/verify_deck.py +3483 -0
- package/bundled-assets/skill/vendor/README.md +4 -0
- package/bundled-assets/skill/vendor/codex-ppt/LICENSE +21 -0
- package/bundled-assets/skill/vendor/codex-ppt/assemble_ppt.py +435 -0
- package/bundled-assets/skill/vendor/codex-ppt/codex_ppt_runtime.py +284 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_gen.py +972 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/__init__.py +6 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/atlascloud.py +222 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/base.py +32 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/factory.py +21 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/openai_compatible.py +238 -0
- package/bundled-assets/skill/vendor/codex-ppt/requirements.txt +5 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/205/232/346/224/277/347/272/242/351/243/216/346/240/274.md +98 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/210/233/346/204/217/346/235/202/345/277/227/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/244/215/345/217/244/346/211/201/345/271/263/346/217/222/347/224/273/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/346/212/200/346/234/257/350/247/243/351/207/212/351/243/216.md +86 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/347/231/275/346/235/277/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/231/345/255/246/350/257/276/344/273/266/351/243/216.md +107 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/260/346/215/256/344/273/252/350/241/250/347/233/230/351/243/216.md +73 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/205/347/210/275/344/270/223/344/270/232/351/243/216.md +87 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/251/346/232/226/346/211/213/345/267/245/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//347/224/265/345/255/220/345/242/250/346/260/264/346/235/202/345/277/227/351/243/216.md +86 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//347/247/221/347/240/224/347/255/224/350/276/251/351/243/216.md +138 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//351/272/246/350/202/257/351/224/241/351/243/216/346/240/274.md +119 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/LICENSE +21 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/SKILL.md +171 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/agents/openai.yaml +4 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/__init__.py +1 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/cli.py +25 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/__init__.py +1 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_input_normalization.py +355 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_page_artifacts.py +132 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/build_pptx_from_manifest.py +1029 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/configure_image_backend.py +52 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py +214 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py +179 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py +96 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/formula_renderer.py +254 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/image_gen.py +206 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/main.py +795 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/make_page_contact_sheet.py +28 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py +140 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py +212 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py +54 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_text_metrics.py +334 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/path_geometry.py +174 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/prepare_deck_run.py +209 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/process_asset_sheet.py +104 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_imagegen_result.py +118 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_dispatch.py +83 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_result.py +130 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/remove_chroma_key.py +441 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/reset_page_job.py +74 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/runtime_env.py +283 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/split_alpha_components.py +323 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/text_hints.py +309 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/validate_pptx.py +873 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/pyproject.toml +29 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/prompts/page-worker.md +47 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/cli-helper.md +282 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/manifest-schema.md +423 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/page-decision-tree.md +301 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/scripts/build-page-worker-prompt.py +134 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +11423 -0
- package/lib/index.js +2638 -0
- package/package.json +140 -4
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Shared cross-platform runtime helpers for oil-slide scripts.
|
|
3
|
+
|
|
4
|
+
Provides:
|
|
5
|
+
- UTF-8 stdio configuration for piped/redirected streams (fixes Windows GBK UnicodeEncodeError).
|
|
6
|
+
- Unified Chrome/Chromium/Edge discovery across macOS, Linux, and Windows.
|
|
7
|
+
- Playwright cached Chromium/headless-shell discovery (all valid installs, highest numeric revision first).
|
|
8
|
+
- Resilient Playwright Chromium launch with clean fallback order.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import shutil
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def configure_utf8_stdio() -> None:
|
|
21
|
+
"""Reconfigure non-TTY stdout/stderr to UTF-8 so piped JSON/Chinese never fails on Windows GBK."""
|
|
22
|
+
for stream in (sys.stdout, sys.stderr):
|
|
23
|
+
if stream is None:
|
|
24
|
+
continue
|
|
25
|
+
try:
|
|
26
|
+
if not stream.isatty() and hasattr(stream, "reconfigure"):
|
|
27
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
28
|
+
except Exception:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _is_windows() -> bool:
|
|
33
|
+
return os.name == "nt" or sys.platform == "win32"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _is_executable_file(path: Path) -> bool:
|
|
37
|
+
try:
|
|
38
|
+
if not path.is_file():
|
|
39
|
+
return False
|
|
40
|
+
if _is_windows():
|
|
41
|
+
return True
|
|
42
|
+
return os.access(path, os.X_OK)
|
|
43
|
+
except OSError:
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def find_chrome_binary(explicit: str | None = None) -> str | None:
|
|
48
|
+
"""Locate a system Chrome/Chromium/Edge executable across macOS, Linux, and Windows."""
|
|
49
|
+
candidates: list[str] = []
|
|
50
|
+
|
|
51
|
+
if explicit and explicit.strip():
|
|
52
|
+
candidates.append(explicit.strip())
|
|
53
|
+
|
|
54
|
+
for env_key in ("CHROME_BIN", "CHROMIUM_BIN"):
|
|
55
|
+
env_val = (os.environ.get(env_key) or "").strip()
|
|
56
|
+
if env_val:
|
|
57
|
+
candidates.append(env_val)
|
|
58
|
+
|
|
59
|
+
for cmd in ("google-chrome", "chromium", "chromium-browser", "chrome", "msedge"):
|
|
60
|
+
found = shutil.which(cmd)
|
|
61
|
+
if found:
|
|
62
|
+
candidates.append(found)
|
|
63
|
+
|
|
64
|
+
if _is_windows():
|
|
65
|
+
for root_env in ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA"):
|
|
66
|
+
base = (os.environ.get(root_env) or "").strip()
|
|
67
|
+
if base:
|
|
68
|
+
base_p = Path(base)
|
|
69
|
+
candidates.extend(
|
|
70
|
+
[
|
|
71
|
+
str(base_p / "Google" / "Chrome" / "Application" / "chrome.exe"),
|
|
72
|
+
str(base_p / "Microsoft" / "Edge" / "Application" / "msedge.exe"),
|
|
73
|
+
str(base_p / "Chromium" / "Application" / "chrome.exe"),
|
|
74
|
+
]
|
|
75
|
+
)
|
|
76
|
+
elif sys.platform == "darwin":
|
|
77
|
+
candidates.extend(
|
|
78
|
+
[
|
|
79
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
80
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
81
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
82
|
+
]
|
|
83
|
+
)
|
|
84
|
+
else:
|
|
85
|
+
candidates.extend(
|
|
86
|
+
[
|
|
87
|
+
"/usr/bin/google-chrome",
|
|
88
|
+
"/usr/bin/chromium",
|
|
89
|
+
"/usr/bin/chromium-browser",
|
|
90
|
+
"/usr/bin/microsoft-edge",
|
|
91
|
+
]
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
seen: set[str] = set()
|
|
95
|
+
for cand in candidates:
|
|
96
|
+
if not cand or cand in seen:
|
|
97
|
+
continue
|
|
98
|
+
seen.add(cand)
|
|
99
|
+
cand_p = Path(cand)
|
|
100
|
+
if _is_executable_file(cand_p):
|
|
101
|
+
return str(cand_p)
|
|
102
|
+
return None
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def iter_playwright_cached_chromiums() -> list[str]:
|
|
106
|
+
"""Return all valid cached Playwright Chromium / headless-shell binaries, newest revision first."""
|
|
107
|
+
pw_roots: list[Path] = []
|
|
108
|
+
pw_env = (os.environ.get("PLAYWRIGHT_BROWSERS_PATH") or "").strip()
|
|
109
|
+
if pw_env and pw_env != "0":
|
|
110
|
+
pw_roots.append(Path(pw_env))
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
home_dir: Path | None = Path.home()
|
|
114
|
+
except RuntimeError:
|
|
115
|
+
home_dir = None
|
|
116
|
+
|
|
117
|
+
if _is_windows():
|
|
118
|
+
local_app = (os.environ.get("LOCALAPPDATA") or "").strip()
|
|
119
|
+
if local_app:
|
|
120
|
+
pw_roots.append(Path(local_app) / "ms-playwright")
|
|
121
|
+
elif home_dir is not None:
|
|
122
|
+
pw_roots.append(home_dir / "AppData" / "Local" / "ms-playwright")
|
|
123
|
+
elif sys.platform == "darwin":
|
|
124
|
+
pw_roots.append(Path("/ms-playwright"))
|
|
125
|
+
if home_dir is not None:
|
|
126
|
+
pw_roots.extend(
|
|
127
|
+
[
|
|
128
|
+
home_dir / "Library" / "Caches" / "ms-playwright",
|
|
129
|
+
home_dir / ".cache" / "ms-playwright",
|
|
130
|
+
]
|
|
131
|
+
)
|
|
132
|
+
else:
|
|
133
|
+
xdg_cache = (os.environ.get("XDG_CACHE_HOME") or "").strip()
|
|
134
|
+
if xdg_cache:
|
|
135
|
+
pw_roots.append(Path(xdg_cache) / "ms-playwright")
|
|
136
|
+
if home_dir is not None:
|
|
137
|
+
pw_roots.append(home_dir / ".cache" / "ms-playwright")
|
|
138
|
+
pw_roots.append(Path("/ms-playwright"))
|
|
139
|
+
if home_dir is not None:
|
|
140
|
+
pw_roots.append(home_dir / "Library" / "Caches" / "ms-playwright")
|
|
141
|
+
|
|
142
|
+
if _is_windows():
|
|
143
|
+
full_rel_bins = (
|
|
144
|
+
"chrome-win64/chrome.exe",
|
|
145
|
+
"chrome-win/chrome.exe",
|
|
146
|
+
)
|
|
147
|
+
shell_rel_bins = (
|
|
148
|
+
"chrome-headless-shell-win64/chrome-headless-shell.exe",
|
|
149
|
+
"chrome-headless-shell-win32/chrome-headless-shell.exe",
|
|
150
|
+
"chrome-win64/headless_shell.exe",
|
|
151
|
+
"chrome-win/headless_shell.exe",
|
|
152
|
+
)
|
|
153
|
+
elif sys.platform == "darwin":
|
|
154
|
+
full_rel_bins = (
|
|
155
|
+
"chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",
|
|
156
|
+
"chrome-mac-x64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing",
|
|
157
|
+
"chrome-mac-arm64/Chromium.app/Contents/MacOS/Chromium",
|
|
158
|
+
"chrome-mac-x64/Chromium.app/Contents/MacOS/Chromium",
|
|
159
|
+
"chrome-mac/Chromium.app/Contents/MacOS/Chromium",
|
|
160
|
+
)
|
|
161
|
+
shell_rel_bins = (
|
|
162
|
+
"chrome-headless-shell-mac-arm64/chrome-headless-shell",
|
|
163
|
+
"chrome-headless-shell-mac-x64/chrome-headless-shell",
|
|
164
|
+
"chrome-mac-arm64/headless_shell",
|
|
165
|
+
"chrome-mac-x64/headless_shell",
|
|
166
|
+
"chrome-mac/headless_shell",
|
|
167
|
+
)
|
|
168
|
+
else:
|
|
169
|
+
full_rel_bins = (
|
|
170
|
+
"chrome-linux64/chrome",
|
|
171
|
+
"chrome-linux-arm64/chrome",
|
|
172
|
+
"chrome-linux/chrome",
|
|
173
|
+
)
|
|
174
|
+
shell_rel_bins = (
|
|
175
|
+
"chrome-headless-shell-linux64/chrome-headless-shell",
|
|
176
|
+
"chrome-headless-shell-linux-arm64/chrome-headless-shell",
|
|
177
|
+
"chrome-linux64/headless_shell",
|
|
178
|
+
"chrome-linux/headless_shell",
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
rev_re = re.compile(r"^(chromium|chromium_headless_shell)-(\d+)$")
|
|
182
|
+
|
|
183
|
+
def _rev_sort_key(p: Path) -> tuple[int, int, str]:
|
|
184
|
+
m = rev_re.match(p.name)
|
|
185
|
+
if not m:
|
|
186
|
+
return (-1, -1, p.name)
|
|
187
|
+
kind_rank = 1 if m.group(1) == "chromium" else 0
|
|
188
|
+
return (int(m.group(2)), kind_rank, p.name)
|
|
189
|
+
|
|
190
|
+
results: list[str] = []
|
|
191
|
+
seen_bins: set[str] = set()
|
|
192
|
+
seen_roots: set[str] = set()
|
|
193
|
+
for pw_root in pw_roots:
|
|
194
|
+
root_key = str(pw_root)
|
|
195
|
+
if root_key in seen_roots:
|
|
196
|
+
continue
|
|
197
|
+
seen_roots.add(root_key)
|
|
198
|
+
try:
|
|
199
|
+
if not pw_root.is_dir():
|
|
200
|
+
continue
|
|
201
|
+
rev_dirs = sorted(
|
|
202
|
+
(p for p in pw_root.iterdir() if p.is_dir() and rev_re.match(p.name)),
|
|
203
|
+
key=_rev_sort_key,
|
|
204
|
+
reverse=True,
|
|
205
|
+
)
|
|
206
|
+
except OSError:
|
|
207
|
+
continue
|
|
208
|
+
|
|
209
|
+
for rev_dir in rev_dirs:
|
|
210
|
+
rel_bins = full_rel_bins if rev_dir.name.startswith("chromium-") else shell_rel_bins
|
|
211
|
+
for rel_bin in rel_bins:
|
|
212
|
+
cand_p = rev_dir / rel_bin
|
|
213
|
+
if _is_executable_file(cand_p):
|
|
214
|
+
cand_str = str(cand_p)
|
|
215
|
+
if cand_str not in seen_bins:
|
|
216
|
+
seen_bins.add(cand_str)
|
|
217
|
+
results.append(cand_str)
|
|
218
|
+
return results
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def find_playwright_cached_chromium() -> str | None:
|
|
222
|
+
"""Locate the highest-revision cached Playwright Chromium or headless shell binary."""
|
|
223
|
+
cached = iter_playwright_cached_chromiums()
|
|
224
|
+
return cached[0] if cached else None
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def find_browser(explicit: str | None = None) -> str | None:
|
|
228
|
+
"""Locate Chrome/Chromium/Edge (explicit, CHROME_BIN/BROWSER_BIN, system install, or Playwright cache)."""
|
|
229
|
+
if explicit and explicit.strip():
|
|
230
|
+
cand = Path(explicit.strip())
|
|
231
|
+
if _is_executable_file(cand):
|
|
232
|
+
return str(cand)
|
|
233
|
+
for env_key in ("CHROME_BIN", "BROWSER_BIN", "CHROMIUM_BIN"):
|
|
234
|
+
env_val = (os.environ.get(env_key) or "").strip()
|
|
235
|
+
if env_val:
|
|
236
|
+
cand = Path(env_val)
|
|
237
|
+
if _is_executable_file(cand):
|
|
238
|
+
return str(cand)
|
|
239
|
+
found = find_chrome_binary()
|
|
240
|
+
if found:
|
|
241
|
+
return found
|
|
242
|
+
return find_playwright_cached_chromium()
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
_LAUNCH_FALLBACK_TOKENS = (
|
|
246
|
+
"executable doesn't exist",
|
|
247
|
+
"executable does not exist",
|
|
248
|
+
"failed to launch",
|
|
249
|
+
"could not find browser",
|
|
250
|
+
"chromium distribution",
|
|
251
|
+
"chrome distribution",
|
|
252
|
+
"msedge distribution",
|
|
253
|
+
"distribution is not found",
|
|
254
|
+
"is not installed",
|
|
255
|
+
"no such file or directory",
|
|
256
|
+
"cannot find the file",
|
|
257
|
+
"enoent",
|
|
258
|
+
"eacces",
|
|
259
|
+
"playwright install",
|
|
260
|
+
"spawn ",
|
|
261
|
+
"host system is missing dependencies",
|
|
262
|
+
"missing dependencies to run browsers",
|
|
263
|
+
"target page, context or browser has been closed",
|
|
264
|
+
"browser logs:",
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _is_transient_launch_error(exc: BaseException) -> bool:
|
|
269
|
+
"""Return True only for browser-missing / binary-spawn errors that merit fallback."""
|
|
270
|
+
if isinstance(exc, (TypeError, ValueError, KeyError, AttributeError)):
|
|
271
|
+
return False
|
|
272
|
+
if isinstance(exc, (FileNotFoundError, PermissionError, OSError)):
|
|
273
|
+
return True
|
|
274
|
+
msg = str(exc).lower()
|
|
275
|
+
return any(tok in msg for tok in _LAUNCH_FALLBACK_TOKENS)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def launch_chromium(
|
|
279
|
+
playwright_obj: Any,
|
|
280
|
+
*,
|
|
281
|
+
headless: bool = True,
|
|
282
|
+
args: list[str] | None = None,
|
|
283
|
+
executable_path: str | None = None,
|
|
284
|
+
chromium_sandbox: bool | None = None,
|
|
285
|
+
discover_system: bool = True,
|
|
286
|
+
) -> Any:
|
|
287
|
+
"""Launch Playwright Chromium with resilient cross-platform fallback order.
|
|
288
|
+
|
|
289
|
+
Order:
|
|
290
|
+
1. Explicit caller/env `executable_path` (when provided).
|
|
291
|
+
2. Default Playwright bundled Chromium (no `executable_path` or `channel`).
|
|
292
|
+
3. All discovered cached Playwright Chromium / headless-shell binaries (newest revision first).
|
|
293
|
+
4. Auto-discovered system Chrome/Edge (`find_chrome_binary()`, when `discover_system=True`).
|
|
294
|
+
5. `channel="chrome"`, then `channel="msedge"`.
|
|
295
|
+
"""
|
|
296
|
+
base_kw: dict[str, Any] = {"headless": headless}
|
|
297
|
+
if args is not None:
|
|
298
|
+
base_kw["args"] = list(args)
|
|
299
|
+
if chromium_sandbox is not None:
|
|
300
|
+
base_kw["chromium_sandbox"] = chromium_sandbox
|
|
301
|
+
|
|
302
|
+
attempts: list[dict[str, Any]] = []
|
|
303
|
+
seen_sigs: set[tuple[str | None, str | None]] = set()
|
|
304
|
+
|
|
305
|
+
def _add_attempt(exec_path: str | None = None, channel: str | None = None) -> None:
|
|
306
|
+
sig = (exec_path, channel)
|
|
307
|
+
if sig in seen_sigs:
|
|
308
|
+
return
|
|
309
|
+
seen_sigs.add(sig)
|
|
310
|
+
kw = dict(base_kw)
|
|
311
|
+
if exec_path:
|
|
312
|
+
kw["executable_path"] = exec_path
|
|
313
|
+
if channel:
|
|
314
|
+
kw["channel"] = channel
|
|
315
|
+
attempts.append(kw)
|
|
316
|
+
|
|
317
|
+
resolved_exec = executable_path.strip() if isinstance(executable_path, str) and executable_path.strip() else None
|
|
318
|
+
if not resolved_exec:
|
|
319
|
+
for env_key in ("CHROME_BIN", "CHROMIUM_BIN", "OIL_CHROME_BIN"):
|
|
320
|
+
env_val = (os.environ.get(env_key) or "").strip()
|
|
321
|
+
if env_val and _is_executable_file(Path(env_val)):
|
|
322
|
+
resolved_exec = str(Path(env_val))
|
|
323
|
+
break
|
|
324
|
+
if resolved_exec:
|
|
325
|
+
_add_attempt(exec_path=resolved_exec)
|
|
326
|
+
|
|
327
|
+
# Default Playwright bundled Chromium
|
|
328
|
+
_add_attempt()
|
|
329
|
+
# All discovered cached Playwright Chromium / headless-shell binaries (newest revision first)
|
|
330
|
+
for cached_exec in iter_playwright_cached_chromiums():
|
|
331
|
+
_add_attempt(exec_path=cached_exec)
|
|
332
|
+
# Auto-discovered system Chrome/Edge binary (after Playwright's own cache)
|
|
333
|
+
if discover_system:
|
|
334
|
+
sys_chrome = find_chrome_binary()
|
|
335
|
+
if sys_chrome:
|
|
336
|
+
_add_attempt(exec_path=sys_chrome)
|
|
337
|
+
# System channels via Playwright
|
|
338
|
+
_add_attempt(channel="chrome")
|
|
339
|
+
_add_attempt(channel="msedge")
|
|
340
|
+
|
|
341
|
+
last_exc: Exception | None = None
|
|
342
|
+
for kw in attempts:
|
|
343
|
+
try:
|
|
344
|
+
return playwright_obj.chromium.launch(**kw)
|
|
345
|
+
except Exception as exc:
|
|
346
|
+
if not _is_transient_launch_error(exc):
|
|
347
|
+
raise
|
|
348
|
+
last_exc = exc
|
|
349
|
+
|
|
350
|
+
assert last_exc is not None
|
|
351
|
+
raise last_exc
|