Files
reverse-engineering-anything/scripts/lint/rules/no-raw-cdp-session.mjs
T
morluto 254bb21857 refactor(browser): send only CDP commands with registered result schemas (#10666)
* refactor(browser): send only CDP commands with registered result schemas

* refactor(browser): open Playwright CDP sessions only through the registered-command owner

* fix(browser): keep the restore obligation for an applied override with a malformed reply

A schema-rejected success reply means the browser applied the Emulation
override, so the attached environment owner records the reset obligation
before reporting the protocol error. Only a rejected or unanswered command
leaves no obligation.

* refactor(browser): open verifier-script CDP sessions through the registered-command owner (#10710)

* fix(browser): register the CDP commands JavaScript verifiers send

The verifier scripts send Browser.close, Page.createIsolatedWorld, Page.navigate, Page.reload, Target.activateTarget, Target.closeTarget and Target.createTarget through CdpConnection, which now admits every reply through its command's result schema. Register those schemas, refuse an unregistered run-time name as a typed malformed reply instead of a TypeError, and check script send literals against the registry.

* fix(browser): keep Target.closeTarget's success member for the verifiers
2026-11-15 14:49:33 +08:00

38 lines
996 B
JavaScript

const RAW_SESSION_FACTORIES = new Set([
"newCDPSession",
"newBrowserCDPSession",
]);
const propertyName = (member) => {
if (!member.computed && member.property.type === "Identifier")
return member.property.name;
if (member.computed && member.property.type === "Literal")
return typeof member.property.value === "string"
? member.property.value
: undefined;
return undefined;
};
export default {
meta: {
type: "problem",
docs: {
description:
"Open Playwright CDP sessions only through the registered-command owner.",
},
schema: [],
messages: {
raw: "Use newPlaywrightCdpSession so every command is registered and every reply is admitted by its result schema.",
},
},
create(context) {
return {
MemberExpression(node) {
const name = propertyName(node);
if (name !== undefined && RAW_SESSION_FACTORIES.has(name))
context.report({ node, messageId: "raw" });
},
};
},
};