fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

View File

@@ -0,0 +1,131 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var playwrightConnection_exports = {};
__export(playwrightConnection_exports, {
PlaywrightConnection: () => PlaywrightConnection
});
module.exports = __toCommonJS(playwrightConnection_exports);
var import_server = require("../server");
var import_android = require("../server/android/android");
var import_browser = require("../server/browser");
var import_debugControllerDispatcher = require("../server/dispatchers/debugControllerDispatcher");
var import_profiler = require("../server/utils/profiler");
var import_utils = require("../utils");
var import_debugLogger = require("../server/utils/debugLogger");
class PlaywrightConnection {
constructor(semaphore, transport, controller, playwright, initialize, id) {
this._cleanups = [];
this._disconnected = false;
this._transport = transport;
this._semaphore = semaphore;
this._id = id;
this._profileName = (/* @__PURE__ */ new Date()).toISOString();
const lock = this._semaphore.acquire();
this._dispatcherConnection = new import_server.DispatcherConnection();
this._dispatcherConnection.onmessage = async (message) => {
await lock;
if (!transport.isClosed()) {
const messageString = JSON.stringify(message);
if (import_debugLogger.debugLogger.isEnabled("server:channel"))
import_debugLogger.debugLogger.log("server:channel", `[${this._id}] ${(0, import_utils.monotonicTime)() * 1e3} SEND \u25BA ${messageString}`);
if (import_debugLogger.debugLogger.isEnabled("server:metadata"))
this.logServerMetadata(message, messageString, "SEND");
transport.send(messageString);
}
};
transport.on("message", async (message) => {
await lock;
const messageString = Buffer.from(message).toString();
const jsonMessage = JSON.parse(messageString);
if (import_debugLogger.debugLogger.isEnabled("server:channel"))
import_debugLogger.debugLogger.log("server:channel", `[${this._id}] ${(0, import_utils.monotonicTime)() * 1e3} \u25C0 RECV ${messageString}`);
if (import_debugLogger.debugLogger.isEnabled("server:metadata"))
this.logServerMetadata(jsonMessage, messageString, "RECV");
this._dispatcherConnection.dispatch(jsonMessage);
});
transport.on("close", () => this._onDisconnect());
transport.on("error", (error) => this._onDisconnect(error));
if (controller) {
import_debugLogger.debugLogger.log("server", `[${this._id}] engaged reuse controller mode`);
this._root = new import_debugControllerDispatcher.DebugControllerDispatcher(this._dispatcherConnection, playwright.debugController);
return;
}
this._root = new import_server.RootDispatcher(this._dispatcherConnection, async (scope, params) => {
await (0, import_profiler.startProfiling)();
const options = await initialize();
if (options.preLaunchedBrowser) {
const browser = options.preLaunchedBrowser;
browser.options.sdkLanguage = params.sdkLanguage;
browser.on(import_browser.Browser.Events.Disconnected, () => {
this.close({ code: 1001, reason: "Browser closed" });
});
}
if (options.preLaunchedAndroidDevice) {
const androidDevice = options.preLaunchedAndroidDevice;
androidDevice.on(import_android.AndroidDevice.Events.Close, () => {
this.close({ code: 1001, reason: "Android device disconnected" });
});
}
if (options.dispose)
this._cleanups.push(options.dispose);
const dispatcher = new import_server.PlaywrightDispatcher(scope, playwright, options);
this._cleanups.push(() => dispatcher.cleanup());
return dispatcher;
});
}
async _onDisconnect(error) {
if (this._disconnected)
return;
this._disconnected = true;
import_debugLogger.debugLogger.log("server", `[${this._id}] disconnected. error: ${error}`);
await this._root.stopPendingOperations(new Error("Disconnected")).catch(() => {
});
this._root._dispose();
import_debugLogger.debugLogger.log("server", `[${this._id}] starting cleanup`);
for (const cleanup of this._cleanups)
await cleanup().catch(() => {
});
await (0, import_profiler.stopProfiling)(this._profileName);
this._semaphore.release();
import_debugLogger.debugLogger.log("server", `[${this._id}] finished cleanup`);
}
logServerMetadata(message, messageString, direction) {
const serverLogMetadata = {
wallTime: Date.now(),
id: message.id,
guid: message.guid,
method: message.method,
payloadSizeInBytes: Buffer.byteLength(messageString, "utf-8")
};
import_debugLogger.debugLogger.log("server:metadata", (direction === "SEND" ? "SEND \u25BA " : "\u25C0 RECV ") + JSON.stringify(serverLogMetadata));
}
async close(reason) {
if (this._disconnected)
return;
import_debugLogger.debugLogger.log("server", `[${this._id}] force closing connection: ${reason?.reason || ""} (${reason?.code || 0})`);
try {
this._transport.close(reason);
} catch (e) {
}
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PlaywrightConnection
});

View File

@@ -0,0 +1,100 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var playwrightPipeServer_exports = {};
__export(playwrightPipeServer_exports, {
PlaywrightPipeServer: () => PlaywrightPipeServer
});
module.exports = __toCommonJS(playwrightPipeServer_exports);
var import_net = __toESM(require("net"));
var import_fs = __toESM(require("fs"));
var import_playwrightConnection = require("./playwrightConnection");
var import_serverTransport = require("./serverTransport");
var import_debugLogger = require("../server/utils/debugLogger");
var import_browser = require("../server/browser");
var import_utils = require("../utils");
class PlaywrightPipeServer {
constructor(browser) {
this._connections = /* @__PURE__ */ new Set();
this._connectionId = 0;
this._browser = browser;
browser.on(import_browser.Browser.Events.Disconnected, () => this.close());
}
async listen(pipeName) {
if (!pipeName.startsWith("\\\\.\\pipe\\")) {
try {
import_fs.default.unlinkSync(pipeName);
} catch {
}
}
this._server = import_net.default.createServer((socket) => {
const id = String(++this._connectionId);
import_debugLogger.debugLogger.log("server", `[${id}] pipe client connected`);
const transport = new import_serverTransport.SocketServerTransport(socket);
const connection = new import_playwrightConnection.PlaywrightConnection(
new import_utils.Semaphore(1),
transport,
false,
this._browser.attribution.playwright,
() => this._initPreLaunchedBrowserMode(id),
id
);
this._connections.add(connection);
transport.on("close", () => this._connections.delete(connection));
});
(0, import_utils.decorateServer)(this._server);
await new Promise((resolve, reject) => {
this._server.listen(pipeName, () => resolve());
this._server.on("error", reject);
});
import_debugLogger.debugLogger.log("server", `Pipe server listening at ${pipeName}`);
}
async _initPreLaunchedBrowserMode(id) {
import_debugLogger.debugLogger.log("server", `[${id}] engaged pre-launched (browser) pipe mode`);
return {
preLaunchedBrowser: this._browser,
sharedBrowser: true,
denyLaunch: true
};
}
async close() {
if (!this._server)
return;
import_debugLogger.debugLogger.log("server", "closing pipe server");
for (const connection of this._connections)
await connection.close({ code: 1001, reason: "Server closing" });
this._connections.clear();
await new Promise((f) => this._server.close(() => f()));
this._server = void 0;
import_debugLogger.debugLogger.log("server", "closed pipe server");
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PlaywrightPipeServer
});

View File

@@ -0,0 +1,339 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var playwrightServer_exports = {};
__export(playwrightServer_exports, {
PlaywrightServer: () => PlaywrightServer
});
module.exports = __toCommonJS(playwrightServer_exports);
var import_playwrightConnection = require("./playwrightConnection");
var import_serverTransport = require("./serverTransport");
var import_playwright = require("../server/playwright");
var import_semaphore = require("../utils/isomorphic/semaphore");
var import_time = require("../utils/isomorphic/time");
var import_wsServer = require("../server/utils/wsServer");
var import_ascii = require("../server/utils/ascii");
var import_userAgent = require("../server/utils/userAgent");
var import_utils = require("../utils");
var import_socksProxy = require("../server/utils/socksProxy");
var import_browser = require("../server/browser");
var import_progress = require("../server/progress");
class PlaywrightServer {
constructor(options) {
this._dontReuseBrowsers = /* @__PURE__ */ new Set();
this._options = options;
if (options.preLaunchedBrowser) {
this._playwright = options.preLaunchedBrowser.attribution.playwright;
this._dontReuse(options.preLaunchedBrowser);
}
if (options.preLaunchedAndroidDevice)
this._playwright = options.preLaunchedAndroidDevice._android.attribution.playwright;
this._playwright ??= (0, import_playwright.createPlaywright)({ sdkLanguage: "javascript", isServer: true });
const browserSemaphore = new import_semaphore.Semaphore(this._options.maxConnections);
const controllerSemaphore = new import_semaphore.Semaphore(1);
const reuseBrowserSemaphore = new import_semaphore.Semaphore(1);
this._wsServer = new import_wsServer.WSServer({
onRequest: (request, response) => {
if (request.method === "GET" && request.url === "/json") {
response.setHeader("Content-Type", "application/json");
response.end(JSON.stringify({
wsEndpointPath: this._options.path
}));
return;
}
response.end("Running");
},
onUpgrade: (request, socket) => {
const uaError = userAgentVersionMatchesErrorMessage(request.headers["user-agent"] || "");
if (uaError)
return { error: `HTTP/${request.httpVersion} 428 Precondition Required\r
\r
${uaError}` };
},
onHeaders: (headers) => {
if (process.env.PWTEST_SERVER_WS_HEADERS)
headers.push(process.env.PWTEST_SERVER_WS_HEADERS);
},
onConnection: (request, url, ws, id) => {
const browserHeader = request.headers["x-playwright-browser"];
const browserName = url.searchParams.get("browser") || (Array.isArray(browserHeader) ? browserHeader[0] : browserHeader) || null;
const proxyHeader = request.headers["x-playwright-proxy"];
const proxyValue = url.searchParams.get("proxy") || (Array.isArray(proxyHeader) ? proxyHeader[0] : proxyHeader);
const launchOptionsHeader = request.headers["x-playwright-launch-options"] || "";
const launchOptionsHeaderValue = Array.isArray(launchOptionsHeader) ? launchOptionsHeader[0] : launchOptionsHeader;
const launchOptionsParam = url.searchParams.get("launch-options");
let launchOptions = { timeout: import_time.DEFAULT_PLAYWRIGHT_LAUNCH_TIMEOUT };
try {
launchOptions = JSON.parse(launchOptionsParam || launchOptionsHeaderValue);
if (!launchOptions.timeout)
launchOptions.timeout = import_time.DEFAULT_PLAYWRIGHT_LAUNCH_TIMEOUT;
} catch (e) {
}
const isExtension = this._options.mode === "extension";
const allowFSPaths = isExtension;
launchOptions = filterLaunchOptions(launchOptions, allowFSPaths);
if (this._options.artifactsDir)
launchOptions.artifactsDir = this._options.artifactsDir;
if (isExtension) {
const connectFilter = url.searchParams.get("connect");
if (connectFilter) {
if (connectFilter !== "first")
throw new Error(`Unknown connect filter: ${connectFilter}`);
return new import_playwrightConnection.PlaywrightConnection(
browserSemaphore,
new import_serverTransport.WebSocketServerTransport(ws),
false,
this._playwright,
() => this._initConnectMode(id, connectFilter, browserName, launchOptions),
id
);
}
if (url.searchParams.has("debug-controller")) {
return new import_playwrightConnection.PlaywrightConnection(
controllerSemaphore,
new import_serverTransport.WebSocketServerTransport(ws),
true,
this._playwright,
async () => {
throw new Error("shouldnt be used");
},
id
);
}
return new import_playwrightConnection.PlaywrightConnection(
reuseBrowserSemaphore,
new import_serverTransport.WebSocketServerTransport(ws),
false,
this._playwright,
() => this._initReuseBrowsersMode(browserName, launchOptions, id),
id
);
}
if (this._options.mode === "launchServer" || this._options.mode === "launchServerShared") {
if (this._options.preLaunchedBrowser) {
return new import_playwrightConnection.PlaywrightConnection(
browserSemaphore,
new import_serverTransport.WebSocketServerTransport(ws),
false,
this._playwright,
() => this._initPreLaunchedBrowserMode(id),
id
);
}
return new import_playwrightConnection.PlaywrightConnection(
browserSemaphore,
new import_serverTransport.WebSocketServerTransport(ws),
false,
this._playwright,
() => this._initPreLaunchedAndroidMode(id),
id
);
}
return new import_playwrightConnection.PlaywrightConnection(
browserSemaphore,
new import_serverTransport.WebSocketServerTransport(ws),
false,
this._playwright,
() => this._initLaunchBrowserMode(browserName, proxyValue, launchOptions, id),
id
);
}
});
}
async _initReuseBrowsersMode(browserName, launchOptions, id) {
import_utils.debugLogger.log("server", `[${id}] engaged reuse browsers mode for ${browserName}`);
const requestedOptions = launchOptionsHash(launchOptions);
let browser = this._playwright.allBrowsers().find((b) => {
if (b.options.name !== browserName)
return false;
if (this._dontReuseBrowsers.has(b))
return false;
const existingOptions = launchOptionsHash({ ...b.options.originalLaunchOptions, timeout: import_time.DEFAULT_PLAYWRIGHT_LAUNCH_TIMEOUT });
return existingOptions === requestedOptions;
});
for (const b of this._playwright.allBrowsers()) {
if (b === browser)
continue;
if (this._dontReuseBrowsers.has(b))
continue;
if (b.options.name === browserName && b.options.channel === launchOptions.channel)
await b.close({ reason: "Connection terminated" });
}
if (!browser) {
const browserType = this._playwright[browserName || "chromium"];
const controller = new import_progress.ProgressController();
browser = await controller.run((progress) => browserType.launch(progress, {
...launchOptions,
headless: !!process.env.PW_DEBUG_CONTROLLER_HEADLESS
}), launchOptions.timeout);
}
return {
preLaunchedBrowser: browser,
denyLaunch: true,
dispose: async () => {
for (const context of browser.contexts()) {
if (!context.pages().length)
await context.close({ reason: "Connection terminated" });
}
}
};
}
async _initConnectMode(id, filter, browserName, launchOptions) {
browserName ??= "chromium";
import_utils.debugLogger.log("server", `[${id}] engaged connect mode`);
let browser = this._playwright.allBrowsers().find((b) => b.options.name === browserName);
if (!browser) {
const browserType = this._playwright[browserName];
const controller = new import_progress.ProgressController();
browser = await controller.run((progress) => browserType.launch(progress, launchOptions), launchOptions.timeout);
this._dontReuse(browser);
}
return {
preLaunchedBrowser: browser,
denyLaunch: true,
sharedBrowser: true
};
}
async _initPreLaunchedBrowserMode(id) {
import_utils.debugLogger.log("server", `[${id}] engaged pre-launched (browser) mode`);
const browser = this._options.preLaunchedBrowser;
for (const b of this._playwright.allBrowsers()) {
if (b !== browser)
await b.close({ reason: "Connection terminated" });
}
return {
preLaunchedBrowser: browser,
socksProxy: this._options.preLaunchedSocksProxy,
sharedBrowser: this._options.mode === "launchServerShared",
denyLaunch: true
};
}
async _initPreLaunchedAndroidMode(id) {
import_utils.debugLogger.log("server", `[${id}] engaged pre-launched (Android) mode`);
const androidDevice = this._options.preLaunchedAndroidDevice;
return {
preLaunchedAndroidDevice: androidDevice,
denyLaunch: true
};
}
async _initLaunchBrowserMode(browserName, proxyValue, launchOptions, id) {
import_utils.debugLogger.log("server", `[${id}] engaged launch mode for "${browserName}"`);
let socksProxy;
if (proxyValue) {
socksProxy = new import_socksProxy.SocksProxy();
socksProxy.setPattern(proxyValue);
launchOptions.socksProxyPort = await socksProxy.listen(0);
import_utils.debugLogger.log("server", `[${id}] started socks proxy on port ${launchOptions.socksProxyPort}`);
} else {
launchOptions.socksProxyPort = void 0;
}
const browserType = this._playwright[browserName];
const controller = new import_progress.ProgressController();
const browser = await controller.run((progress) => browserType.launch(progress, launchOptions), launchOptions.timeout);
this._dontReuseBrowsers.add(browser);
return {
preLaunchedBrowser: browser,
socksProxy,
denyLaunch: true,
dispose: async () => {
await browser.close({ reason: "Connection terminated" });
socksProxy?.close();
}
};
}
_dontReuse(browser) {
this._dontReuseBrowsers.add(browser);
browser.on(import_browser.Browser.Events.Disconnected, () => {
this._dontReuseBrowsers.delete(browser);
});
}
async listen(port = 0, hostname) {
return this._wsServer.listen(port, hostname, this._options.path);
}
async close() {
await this._wsServer.close();
}
}
function userAgentVersionMatchesErrorMessage(userAgent) {
const match = userAgent.match(/^Playwright\/(\d+\.\d+\.\d+)/);
if (!match) {
return;
}
const received = match[1].split(".").slice(0, 2).join(".");
const expected = (0, import_userAgent.getPlaywrightVersion)(true);
if (received !== expected) {
return (0, import_ascii.wrapInASCIIBox)([
`Playwright version mismatch:`,
` - server version: v${expected}`,
` - client version: v${received}`,
``,
`If you are using VSCode extension, restart VSCode.`,
``,
`If you are connecting to a remote service,`,
`keep your local Playwright version in sync`,
`with the remote service version.`,
``,
`<3 Playwright Team`
].join("\n"), 1);
}
}
function launchOptionsHash(options) {
const copy = { ...options };
for (const k of Object.keys(copy)) {
const key = k;
if (copy[key] === defaultLaunchOptions[key])
delete copy[key];
}
for (const key of optionsThatAllowBrowserReuse)
delete copy[key];
return JSON.stringify(copy);
}
function filterLaunchOptions(options, allowFSPaths) {
return {
channel: options.channel,
args: options.args,
ignoreAllDefaultArgs: options.ignoreAllDefaultArgs,
ignoreDefaultArgs: options.ignoreDefaultArgs,
timeout: options.timeout,
headless: options.headless,
proxy: options.proxy,
chromiumSandbox: options.chromiumSandbox,
firefoxUserPrefs: options.firefoxUserPrefs,
slowMo: options.slowMo,
executablePath: (0, import_utils.isUnderTest)() || allowFSPaths ? options.executablePath : void 0,
downloadsPath: allowFSPaths ? options.downloadsPath : void 0,
artifactsDir: (0, import_utils.isUnderTest)() || allowFSPaths ? options.artifactsDir : void 0
};
}
const defaultLaunchOptions = {
ignoreAllDefaultArgs: false,
handleSIGINT: false,
handleSIGTERM: false,
handleSIGHUP: false,
headless: true
};
const optionsThatAllowBrowserReuse = [
"headless",
"timeout",
"tracesDir",
"artifactsDir"
];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PlaywrightServer
});

View File

@@ -0,0 +1,73 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var playwrightWebSocketServer_exports = {};
__export(playwrightWebSocketServer_exports, {
PlaywrightWebSocketServer: () => PlaywrightWebSocketServer
});
module.exports = __toCommonJS(playwrightWebSocketServer_exports);
var import_playwrightConnection = require("./playwrightConnection");
var import_serverTransport = require("./serverTransport");
var import_debugLogger = require("../server/utils/debugLogger");
var import_browser = require("../server/browser");
var import_utils = require("../utils");
var import_wsServer = require("../server/utils/wsServer");
class PlaywrightWebSocketServer {
constructor(browser, path) {
this._browser = browser;
browser.on(import_browser.Browser.Events.Disconnected, () => this.close());
const semaphore = new import_utils.Semaphore(Infinity);
this._wsServer = new import_wsServer.WSServer({
onRequest: (request, response) => {
response.end("Running");
},
onUpgrade: () => void 0,
onHeaders: () => {
},
onConnection: (request, url, ws, id) => {
import_debugLogger.debugLogger.log("server", `[${id}] ws client connected`);
return new import_playwrightConnection.PlaywrightConnection(
semaphore,
new import_serverTransport.WebSocketServerTransport(ws),
false,
this._browser.attribution.playwright,
() => this._initPreLaunchedBrowserMode(id),
id
);
}
});
}
async _initPreLaunchedBrowserMode(id) {
import_debugLogger.debugLogger.log("server", `[${id}] engaged pre-launched (browser) ws mode`);
return {
preLaunchedBrowser: this._browser,
sharedBrowser: true,
denyLaunch: true
};
}
async listen(port = 0, hostname, path) {
return await this._wsServer.listen(port, hostname, path || "/");
}
async close() {
await this._wsServer.close();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PlaywrightWebSocketServer
});

View File

@@ -0,0 +1,96 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var serverTransport_exports = {};
__export(serverTransport_exports, {
SocketServerTransport: () => SocketServerTransport,
WebSocketServerTransport: () => WebSocketServerTransport
});
module.exports = __toCommonJS(serverTransport_exports);
var import_events = require("events");
class WebSocketServerTransport {
constructor(ws) {
this._ws = ws;
}
send(message) {
this._ws.send(message);
}
close(reason) {
this._ws.close(reason?.code, reason?.reason);
}
on(event, handler) {
this._ws.on(event, handler);
}
isClosed() {
return this._ws.readyState === this._ws.CLOSING || this._ws.readyState === this._ws.CLOSED;
}
}
class SocketServerTransport extends import_events.EventEmitter {
constructor(socket) {
super();
this._closed = false;
this._pendingBuffers = [];
this._socket = socket;
socket.on("data", (buffer) => this._dispatch(buffer));
socket.on("close", () => {
this._closed = true;
super.emit("close");
});
socket.on("error", (error) => {
super.emit("error", error);
});
}
send(message) {
if (this._closed)
return;
this._socket.write(message);
this._socket.write("\0");
}
close(reason) {
if (this._closed)
return;
this._closed = true;
this._socket.end();
}
isClosed() {
return this._closed;
}
_dispatch(buffer) {
let end = buffer.indexOf("\0");
if (end === -1) {
this._pendingBuffers.push(buffer);
return;
}
this._pendingBuffers.push(buffer.slice(0, end));
const message = Buffer.concat(this._pendingBuffers).toString();
super.emit("message", message);
let start = end + 1;
end = buffer.indexOf("\0", start);
while (end !== -1) {
super.emit("message", buffer.toString(void 0, start, end));
start = end + 1;
end = buffer.indexOf("\0", start);
}
this._pendingBuffers = [buffer.slice(start)];
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
SocketServerTransport,
WebSocketServerTransport
});