remote: the Playwright initializer names every required type of spec 1.62
A client built on the 1.62 spec (playwright-go's newPlaywright) reads chromium, firefox, webkit, android and electron from the Playwright initializer without checking for a missing one and panics: 'fromChannel: expected *channel, got <nil>'. chromium and webkit are BrowserTypes whose calls refuse with a reason; Android and Electron likewise. Announced before Playwright. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef427f767f
commit
5d9ad70f7c
2 files changed
+98
-4
No files matched your search
@@ -67,7 +67,7 @@ from urllib.parse import parse_qs, urlsplit
|
||||
from . import wire
|
||||
from .dispatcher import ProtocolException
|
||||
from .server import (BrowserDispatcher, BrowserTypeDispatcher, JugglerServer,
|
||||
LocalUtilsDispatcher)
|
||||
LocalUtilsDispatcher, RefusingDispatcher)
|
||||
from .transport import _error_payload
|
||||
|
||||
#: The client whose call a worker thread is answering.
|
||||
@@ -180,6 +180,39 @@ class SharedBrowserType(BrowserTypeDispatcher):
|
||||
browser_class = SharedBrowserDispatcher
|
||||
|
||||
|
||||
class UnservedBrowserType(RefusingDispatcher):
|
||||
"""chromium and webkit: in the Playwright initializer because the protocol requires every
|
||||
browser type there (a client's constructor reads all three and does not check for a missing
|
||||
one), and every call on them refuses with the reason. Only firefox is served."""
|
||||
|
||||
TYPE = "BrowserType"
|
||||
REASON = "this server serves one browser, the firefox engine, and not %s"
|
||||
|
||||
def __init__(self, server: Any, name: str) -> None:
|
||||
super().__init__(server, None, {"executablePath": "", "name": name})
|
||||
self.REASON = self.REASON % name
|
||||
|
||||
|
||||
class UnservedAndroid(RefusingDispatcher):
|
||||
"""Required by the 1.62 Playwright initializer; Android is outside what is served."""
|
||||
|
||||
TYPE = "Android"
|
||||
REASON = "Android devices are not served"
|
||||
|
||||
def __init__(self, server: Any) -> None:
|
||||
super().__init__(server, None, {})
|
||||
|
||||
|
||||
class UnservedElectron(RefusingDispatcher):
|
||||
"""Required by the 1.62 Playwright initializer; Electron is outside what is served."""
|
||||
|
||||
TYPE = "Electron"
|
||||
REASON = "Electron is not served"
|
||||
|
||||
def __init__(self, server: Any) -> None:
|
||||
super().__init__(server, None, {})
|
||||
|
||||
|
||||
class RemoteEndpoint:
|
||||
"""The WebSocket side: serves an already-launched browser's registry.
|
||||
|
||||
@@ -215,6 +248,12 @@ class RemoteEndpoint:
|
||||
self._start_error: Optional[BaseException] = None
|
||||
self._lock = threading.Lock()
|
||||
self._closed = False
|
||||
#: The rest of what the Playwright initializer must name (spec 1.62: chromium,
|
||||
#: firefox, webkit, android, electron are all required), created once.
|
||||
self.chromium = UnservedBrowserType(server, "chromium")
|
||||
self.webkit = UnservedBrowserType(server, "webkit")
|
||||
self.android = UnservedAndroid(server)
|
||||
self.electron = UnservedElectron(server)
|
||||
server.endpoint = self
|
||||
|
||||
# ── where it listens ────────────────────────────────────────────────────
|
||||
@@ -409,7 +448,8 @@ class RemoteEndpoint:
|
||||
"""The announce a launched server makes to a client, to it alone and
|
||||
in the order that names nothing the client has not seen."""
|
||||
client.initialized = True
|
||||
for obj in (self.browser_type, self._utils(), self.browser):
|
||||
for obj in (self.browser_type, self.chromium, self.webkit, self.android,
|
||||
self.electron, self._utils(), self.browser):
|
||||
parent = obj.parent.guid if obj.parent is not None else self.server.root_guid
|
||||
client.post_message({"guid": parent, "method": "__create__",
|
||||
"params": {"type": obj.TYPE, "guid": obj.guid,
|
||||
@@ -426,7 +466,11 @@ class RemoteEndpoint:
|
||||
raise ProtocolException("this server has no LocalUtils")
|
||||
|
||||
def _playwright_initializer(self) -> Dict:
|
||||
return {"firefox": self.browser_type.channel,
|
||||
return {"chromium": self.chromium.channel,
|
||||
"firefox": self.browser_type.channel,
|
||||
"webkit": self.webkit.channel,
|
||||
"android": self.android.channel,
|
||||
"electron": self.electron.channel,
|
||||
"utils": self._utils().channel,
|
||||
"preLaunchedBrowser": self.browser.channel}
|
||||
|
||||
|
||||
@@ -103,7 +103,8 @@ def test_initialize_creates_the_launch_server_objects(served):
|
||||
before, reply = run(go())
|
||||
created = [(m["params"]["type"], m["params"]["guid"]) for m in before
|
||||
if m["method"] == "__create__"]
|
||||
assert [t for t, _ in created] == ["BrowserType", "LocalUtils", "Browser", "Playwright"]
|
||||
assert [t for t, _ in created] == ["BrowserType"] * 3 + ["Android", "Electron", "LocalUtils",
|
||||
"Browser", "Playwright"]
|
||||
assert reply["result"] == {"playwright": {"guid": "Playwright"}}
|
||||
playwright = before[-1]["params"]["initializer"]
|
||||
assert playwright["preLaunchedBrowser"] == {"guid": served.browser.guid}
|
||||
@@ -239,3 +240,52 @@ def test_a_client_without_a_page_number_gets_one(served):
|
||||
run(go())
|
||||
numbers = [p["pageNumber"] for _, p in served.browser.seen]
|
||||
assert numbers == [0, 1]
|
||||
|
||||
|
||||
#: The `Playwright` initializer of protocol 1.62 (packages/protocol/spec/playwright.yml): the
|
||||
#: field -> the type it names; required unless it is in OPTIONAL. A client built on it reads every
|
||||
#: required one at construction and does not check for a missing one (playwright-go's
|
||||
#: newPlaywright panics: "fromChannel: expected *channel, got <nil>").
|
||||
SPEC_162_INITIALIZER = {"chromium": "BrowserType", "firefox": "BrowserType", "webkit": "BrowserType",
|
||||
"android": "Android", "electron": "Electron", "utils": "LocalUtils",
|
||||
"preLaunchedBrowser": "Browser", "preConnectedAndroidDevice": "AndroidDevice",
|
||||
"socksSupport": "SocksSupport"}
|
||||
OPTIONAL = {"utils", "preLaunchedBrowser", "preConnectedAndroidDevice", "socksSupport"}
|
||||
|
||||
|
||||
def test_the_playwright_initializer_is_the_one_of_spec_162(served):
|
||||
"""Known-bad: the initializer with firefox, utils and preLaunchedBrowser only."""
|
||||
async def go():
|
||||
async with connect(served.ws_endpoint) as ws:
|
||||
before, _ = await call(ws, 1, "", "initialize", {"sdkLanguage": "javascript"})
|
||||
return before
|
||||
before = run(go())
|
||||
types = {m["params"]["guid"]: m["params"]["type"] for m in before if m["method"] == "__create__"}
|
||||
order = [m["params"]["guid"] for m in before if m["method"] == "__create__"]
|
||||
initializer = before[-1]["params"]["initializer"]
|
||||
assert before[-1]["params"]["type"] == "Playwright"
|
||||
for field, kind in SPEC_162_INITIALIZER.items():
|
||||
if field not in initializer:
|
||||
assert field in OPTIONAL, "required field %s is missing" % field
|
||||
continue
|
||||
guid = initializer[field]["guid"]
|
||||
assert types[guid] == kind, (field, types[guid])
|
||||
assert order.index(guid) < len(order) - 1, "%s is announced after Playwright" % field
|
||||
assert set(initializer) <= set(SPEC_162_INITIALIZER)
|
||||
|
||||
|
||||
def test_chromium_and_webkit_are_real_browser_types_that_refuse_with_a_reason(served):
|
||||
async def go():
|
||||
async with connect(served.ws_endpoint) as ws:
|
||||
before, _ = await call(ws, 1, "", "initialize", {"sdkLanguage": "javascript"})
|
||||
initializer = before[-1]["params"]["initializer"]
|
||||
out = {}
|
||||
for n, name in enumerate(("chromium", "webkit"), start=2):
|
||||
_, reply = await call(ws, n, initializer[name]["guid"], "launch", {})
|
||||
out[name] = reply
|
||||
return out
|
||||
out = run(go())
|
||||
for name, reply in out.items():
|
||||
assert "error" in reply
|
||||
assert name in reply["error"]["error"]["message"]
|
||||
assert "not" in reply["error"]["error"]["message"]
|
||||
Reference in new issue
Block a user