Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions embedding/scenario/playwright_dynamic_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,27 @@ def _install_target_seed_init_script(self) -> None:
self._init_script_installed = True

def _wait_for_service_worker(self, timeout_ms: int = 5000) -> bool:
# Content-script-only MV3 extensions (manifest without background.service_worker)
# never register a service worker. Once launch_persistent_context has loaded the
# extension, it is loaded β€” the content script runs when a matching page is
# navigated. Block here only for extensions that actually declare a worker;
# otherwise extension_loaded stays False forever and the run aborts at the
# extension_not_loaded gate.
if (
self._execution.get("extension_background_type") != "service_worker"
and self._context is not None
and bool(self._execution.get("extension_context_launched", False))
):
self._execution["service_worker_count"] = 0
self._execution["service_worker_urls"] = []
self._execution["service_worker_ready"] = False
self._execution["extension_loaded"] = True
self._execution["extension_load_mode"] = "content_script_only"
prior_err = self._execution.get("extension_load_error")
if prior_err in {"playwright_sync_in_async_loop", "extension_service_worker_not_started_headless_mode_possible"}:
self._execution["extension_load_warning"] = str(prior_err or "")
self._execution["extension_load_error"] = ""
return True
deadline = time.time() + (max(timeout_ms, 0) / 1000.0)
while time.time() < deadline:
workers = []
Expand Down Expand Up @@ -2188,6 +2209,10 @@ def close(self) -> dict:
except Exception as exc:
cleanup_errors.append(f"remove_temp_dir_failed:{exc}")
self._tmp_dirs.clear()
# The unpacked extension dir was just removed above; drop the cached root so the
# next _ensure_context re-extracts from the zip instead of pointing at a deleted
# path (which would surface as manifest_not_found on every scenario after the first).
self._extension_root = None
if not had_user_data_tmp:
self._execution["cleanup_removed_user_data_dir_not_applicable"] = True
if not had_unpacked_tmp:
Expand Down
Loading