patchright-core 1.57.0 → 1.59.0
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/ThirdPartyNotices.txt +2688 -297
- package/browsers.json +23 -22
- package/lib/bootstrap.js +77 -0
- package/lib/cli/browserActions.js +308 -0
- package/lib/cli/driver.js +3 -2
- package/lib/cli/installActions.js +171 -0
- package/lib/cli/program.js +48 -413
- package/lib/client/android.js +4 -4
- package/lib/client/api.js +3 -0
- package/lib/client/browser.js +11 -5
- package/lib/client/browserContext.js +20 -23
- package/lib/client/browserType.js +23 -54
- package/lib/client/cdpSession.js +6 -2
- package/lib/client/channelOwner.js +1 -1
- package/lib/client/clientHelper.js +2 -1
- package/lib/client/clock.js +0 -1
- package/lib/client/{webSocket.js → connect.js} +57 -7
- package/lib/client/connection.js +8 -0
- package/lib/client/consoleMessage.js +3 -0
- package/lib/client/debugger.js +57 -0
- package/lib/client/dialog.js +8 -1
- package/lib/client/disposable.js +76 -0
- package/lib/client/electron.js +1 -0
- package/lib/client/elementHandle.js +1 -1
- package/lib/client/events.js +3 -0
- package/lib/client/fetch.js +2 -4
- package/lib/client/frame.js +9 -13
- package/lib/client/harRouter.js +13 -1
- package/lib/client/jsHandle.js +4 -8
- package/lib/client/locator.js +13 -36
- package/lib/client/network.js +14 -11
- package/lib/client/page.js +44 -50
- package/lib/client/screencast.js +88 -0
- package/lib/client/selectors.js +3 -1
- package/lib/client/tracing.js +11 -5
- package/lib/client/video.js +13 -20
- package/lib/client/worker.js +6 -6
- package/lib/generated/bindingsControllerSource.js +1 -1
- package/lib/generated/clockSource.js +1 -1
- package/lib/generated/injectedScriptSource.js +1 -1
- package/lib/generated/pollingRecorderSource.js +1 -1
- package/lib/generated/storageScriptSource.js +1 -1
- package/lib/generated/utilityScriptSource.js +1 -1
- package/lib/mcpBundle.js +78 -0
- package/lib/mcpBundleImpl.js +91 -0
- package/lib/protocol/serializers.js +5 -0
- package/lib/protocol/validator.js +228 -58
- package/lib/protocol/validatorPrimitives.js +1 -1
- package/lib/remote/playwrightConnection.js +10 -8
- package/lib/remote/playwrightPipeServer.js +100 -0
- package/lib/remote/playwrightServer.js +14 -10
- package/lib/remote/playwrightWebSocketServer.js +73 -0
- package/lib/remote/serverTransport.js +96 -0
- package/lib/server/android/android.js +2 -2
- package/lib/server/artifact.js +1 -1
- package/lib/server/bidi/bidiBrowser.js +80 -14
- package/lib/server/bidi/bidiChromium.js +23 -14
- package/lib/server/bidi/bidiConnection.js +1 -0
- package/lib/server/bidi/bidiDeserializer.js +116 -0
- package/lib/server/bidi/bidiExecutionContext.js +75 -29
- package/lib/server/bidi/bidiFirefox.js +6 -8
- package/lib/server/bidi/bidiNetworkManager.js +40 -12
- package/lib/server/bidi/bidiPage.js +67 -40
- package/lib/server/bidi/third_party/bidiProtocolCore.js +1 -0
- package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
- package/lib/server/browser.js +84 -21
- package/lib/server/browserContext.js +137 -77
- package/lib/server/browserType.js +26 -16
- package/lib/server/chromium/chromium.js +28 -31
- package/lib/server/chromium/chromiumSwitches.js +16 -4
- package/lib/server/chromium/crBrowser.js +40 -27
- package/lib/server/chromium/crConnection.js +0 -5
- package/lib/server/chromium/crDevTools.js +1 -2
- package/lib/server/chromium/crNetworkManager.js +54 -229
- package/lib/server/chromium/crPage.js +74 -260
- package/lib/server/chromium/crServiceWorker.js +7 -14
- package/lib/server/clock.js +33 -41
- package/lib/server/codegen/javascript.js +6 -29
- package/lib/server/console.js +5 -1
- package/lib/server/debugController.js +12 -6
- package/lib/server/debugger.js +40 -47
- package/lib/server/deviceDescriptorsSource.json +137 -137
- package/lib/server/dispatchers/browserContextDispatcher.js +30 -30
- package/lib/server/dispatchers/browserDispatcher.js +11 -5
- package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
- package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
- package/lib/server/dispatchers/dispatcher.js +7 -14
- package/lib/server/dispatchers/disposableDispatcher.js +39 -0
- package/lib/server/dispatchers/electronDispatcher.js +2 -1
- package/lib/server/dispatchers/frameDispatcher.js +7 -7
- package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
- package/lib/server/dispatchers/networkDispatchers.js +6 -5
- package/lib/server/dispatchers/pageDispatcher.js +101 -34
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
- package/lib/server/disposable.js +41 -0
- package/lib/server/dom.js +56 -29
- package/lib/server/download.js +3 -2
- package/lib/server/electron/electron.js +17 -9
- package/lib/server/firefox/ffBrowser.js +9 -29
- package/lib/server/firefox/ffConnection.js +0 -5
- package/lib/server/firefox/ffInput.js +21 -5
- package/lib/server/firefox/ffNetworkManager.js +4 -4
- package/lib/server/firefox/ffPage.js +27 -33
- package/lib/server/firefox/firefox.js +6 -8
- package/lib/server/frameSelectors.js +14 -169
- package/lib/server/frames.js +263 -551
- package/lib/server/har/harRecorder.js +2 -2
- package/lib/server/har/harTracer.js +5 -4
- package/lib/server/input.js +49 -4
- package/lib/server/instrumentation.js +8 -0
- package/lib/server/javascript.js +6 -22
- package/lib/server/launchApp.js +0 -1
- package/lib/server/localUtils.js +6 -6
- package/lib/server/network.js +59 -20
- package/lib/server/overlay.js +138 -0
- package/lib/server/page.js +179 -157
- package/lib/server/progress.js +32 -6
- package/lib/server/recorder/recorderApp.js +84 -104
- package/lib/server/recorder.js +76 -40
- package/lib/server/registry/browserFetcher.js +6 -4
- package/lib/server/registry/index.js +222 -226
- package/lib/server/registry/nativeDeps.js +1 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +3 -0
- package/lib/server/screencast.js +137 -0
- package/lib/server/trace/recorder/snapshotter.js +2 -2
- package/lib/server/trace/recorder/snapshotterInjected.js +21 -1
- package/lib/server/trace/recorder/tracing.js +98 -47
- package/lib/server/trace/viewer/traceViewer.js +24 -21
- package/lib/server/usKeyboardLayout.js +7 -0
- package/lib/server/utils/comparators.js +1 -1
- package/lib/server/utils/disposable.js +32 -0
- package/lib/server/utils/eventsHelper.js +3 -1
- package/lib/server/utils/expectUtils.js +87 -2
- package/lib/server/utils/fileUtils.js +16 -2
- package/lib/server/utils/happyEyeballs.js +15 -12
- package/lib/server/utils/httpServer.js +10 -23
- package/lib/server/utils/network.js +39 -29
- package/lib/server/utils/processLauncher.js +8 -6
- package/lib/server/utils/zipFile.js +2 -2
- package/lib/server/videoRecorder.js +194 -0
- package/lib/server/webkit/webkit.js +4 -6
- package/lib/server/webkit/wkBrowser.js +1 -10
- package/lib/server/webkit/wkConnection.js +1 -6
- package/lib/server/webkit/wkInterceptableRequest.js +29 -1
- package/lib/server/webkit/wkPage.js +88 -57
- package/lib/server/webkit/wkWorkers.js +2 -1
- package/lib/serverRegistry.js +156 -0
- package/lib/tools/backend/browserBackend.js +79 -0
- package/lib/tools/backend/common.js +63 -0
- package/lib/tools/backend/config.js +41 -0
- package/lib/tools/backend/console.js +66 -0
- package/lib/tools/backend/context.js +296 -0
- package/lib/tools/backend/cookies.js +152 -0
- package/lib/tools/backend/devtools.js +69 -0
- package/lib/tools/backend/dialogs.js +59 -0
- package/lib/tools/backend/evaluate.js +64 -0
- package/lib/tools/backend/files.js +60 -0
- package/lib/tools/backend/form.js +64 -0
- package/lib/tools/backend/keyboard.js +155 -0
- package/lib/tools/backend/logFile.js +95 -0
- package/lib/tools/backend/mouse.js +168 -0
- package/lib/tools/backend/navigate.js +106 -0
- package/lib/tools/backend/network.js +135 -0
- package/lib/tools/backend/pdf.js +48 -0
- package/lib/tools/backend/response.js +305 -0
- package/lib/tools/backend/route.js +140 -0
- package/lib/tools/backend/runCode.js +77 -0
- package/lib/tools/backend/screenshot.js +88 -0
- package/lib/tools/backend/sessionLog.js +74 -0
- package/lib/tools/backend/snapshot.js +208 -0
- package/lib/tools/backend/storage.js +68 -0
- package/lib/tools/backend/tab.js +445 -0
- package/lib/tools/backend/tabs.js +67 -0
- package/lib/tools/backend/tool.js +47 -0
- package/lib/tools/backend/tools.js +102 -0
- package/lib/tools/backend/tracing.js +78 -0
- package/lib/tools/backend/utils.js +83 -0
- package/lib/tools/backend/verify.js +151 -0
- package/lib/tools/backend/video.js +98 -0
- package/lib/tools/backend/wait.js +63 -0
- package/lib/tools/backend/webstorage.js +223 -0
- package/lib/tools/cli-client/cli.js +6 -0
- package/lib/tools/cli-client/help.json +399 -0
- package/lib/tools/cli-client/minimist.js +128 -0
- package/lib/tools/cli-client/program.js +350 -0
- package/lib/tools/cli-client/registry.js +176 -0
- package/lib/tools/cli-client/session.js +289 -0
- package/lib/tools/cli-client/skill/SKILL.md +328 -0
- package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
- package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
- package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
- package/lib/tools/cli-client/skill/references/running-code.md +231 -0
- package/lib/tools/cli-client/skill/references/session-management.md +169 -0
- package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
- package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
- package/lib/tools/cli-client/skill/references/tracing.md +139 -0
- package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
- package/lib/tools/cli-daemon/command.js +73 -0
- package/lib/tools/cli-daemon/commands.js +956 -0
- package/lib/tools/cli-daemon/daemon.js +157 -0
- package/lib/tools/cli-daemon/helpGenerator.js +177 -0
- package/lib/tools/cli-daemon/program.js +129 -0
- package/lib/tools/dashboard/appIcon.png +0 -0
- package/lib/tools/dashboard/dashboardApp.js +284 -0
- package/lib/tools/dashboard/dashboardController.js +296 -0
- package/lib/tools/exports.js +60 -0
- package/lib/tools/mcp/browserFactory.js +233 -0
- package/lib/tools/mcp/cdpRelay.js +352 -0
- package/lib/tools/mcp/cli-stub.js +7 -0
- package/lib/tools/mcp/config.d.js +16 -0
- package/lib/tools/mcp/config.js +446 -0
- package/lib/tools/mcp/configIni.js +189 -0
- package/lib/tools/mcp/extensionContextFactory.js +55 -0
- package/lib/tools/mcp/index.js +62 -0
- package/lib/tools/mcp/log.js +35 -0
- package/lib/tools/mcp/program.js +107 -0
- package/lib/tools/mcp/protocol.js +28 -0
- package/lib/tools/mcp/watchdog.js +44 -0
- package/lib/tools/trace/SKILL.md +171 -0
- package/lib/tools/trace/installSkill.js +48 -0
- package/lib/tools/trace/traceActions.js +142 -0
- package/lib/tools/trace/traceAttachments.js +69 -0
- package/lib/tools/trace/traceCli.js +87 -0
- package/lib/tools/trace/traceConsole.js +97 -0
- package/lib/tools/trace/traceErrors.js +55 -0
- package/lib/tools/trace/traceOpen.js +69 -0
- package/lib/tools/trace/traceParser.js +96 -0
- package/lib/tools/trace/traceRequests.js +182 -0
- package/lib/tools/trace/traceScreenshot.js +68 -0
- package/lib/tools/trace/traceSnapshot.js +149 -0
- package/lib/tools/trace/traceUtils.js +153 -0
- package/lib/tools/utils/connect.js +32 -0
- package/lib/tools/utils/mcp/http.js +152 -0
- package/lib/tools/utils/mcp/server.js +230 -0
- package/lib/tools/utils/mcp/tool.js +47 -0
- package/lib/tools/utils/socketConnection.js +108 -0
- package/lib/utils/isomorphic/ariaSnapshot.js +60 -2
- package/lib/utils/isomorphic/formatUtils.js +64 -0
- package/lib/utils/isomorphic/jsonSchema.js +89 -0
- package/lib/utils/isomorphic/lruCache.js +51 -0
- package/lib/utils/isomorphic/mimeType.js +7 -2
- package/lib/utils/isomorphic/protocolFormatter.js +2 -2
- package/lib/utils/isomorphic/protocolMetainfo.js +127 -98
- package/lib/utils/isomorphic/stringUtils.js +49 -0
- package/lib/utils/isomorphic/timeoutRunner.js +3 -3
- package/lib/utils/isomorphic/trace/entries.js +16 -0
- package/lib/utils/isomorphic/trace/snapshotRenderer.js +492 -0
- package/lib/utils/isomorphic/trace/snapshotServer.js +120 -0
- package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -0
- package/lib/utils/isomorphic/trace/traceLoader.js +132 -0
- package/lib/utils/isomorphic/trace/traceModel.js +366 -0
- package/lib/utils/isomorphic/trace/traceModernizer.js +401 -0
- package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -0
- package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -0
- package/lib/utils/isomorphic/urlMatch.js +54 -1
- package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
- package/lib/utils/isomorphic/yaml.js +84 -0
- package/lib/utils.js +8 -2
- package/lib/utilsBundle.js +5 -26
- package/lib/utilsBundleImpl/index.js +172 -173
- package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
- package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
- package/lib/vite/dashboard/index.html +28 -0
- package/lib/vite/htmlReport/index.html +2 -70
- package/lib/vite/htmlReport/report.css +1 -0
- package/lib/vite/htmlReport/report.js +72 -0
- package/lib/vite/recorder/assets/codeMirrorModule-C8KMvO9L.js +32 -0
- package/lib/vite/recorder/assets/{codeMirrorModule-C3UTv-Ge.css → codeMirrorModule-DYBRYzYX.css} +1 -1
- package/lib/vite/recorder/assets/{index-Ri0uHF7I.css → index-BSjZa4pk.css} +1 -1
- package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
- package/lib/vite/recorder/index.html +2 -2
- package/lib/vite/traceViewer/assets/codeMirrorModule-DS0FLvoc.js +32 -0
- package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
- package/lib/vite/traceViewer/{codeMirrorModule.C3UTv-Ge.css → codeMirrorModule.DYBRYzYX.css} +1 -1
- package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
- package/lib/vite/traceViewer/index.CzXZzn5A.css +1 -0
- package/lib/vite/traceViewer/index.Dtstcb7U.js +2 -0
- package/lib/vite/traceViewer/index.html +4 -4
- package/lib/vite/traceViewer/sw.bundle.js +5 -3
- package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/lib/zipBundleImpl.js +2 -2
- package/lib/zodBundle.js +39 -0
- package/lib/zodBundleImpl.js +40 -0
- package/package.json +7 -1
- package/types/protocol.d.ts +1696 -221
- package/types/types.d.ts +879 -112
- package/lib/server/bidi/third_party/bidiDeserializer.js +0 -98
- package/lib/server/chromium/videoRecorder.js +0 -115
- package/lib/server/pageBinding.js +0 -87
- package/lib/server/trace/test/inMemorySnapshotter.js +0 -87
- package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +0 -248
- package/lib/vite/recorder/assets/codeMirrorModule-CBbSe-ZI.js +0 -25
- package/lib/vite/recorder/assets/index-CpZVd2nA.js +0 -193
- package/lib/vite/traceViewer/assets/codeMirrorModule-DHz0wP2C.js +0 -25
- package/lib/vite/traceViewer/assets/defaultSettingsView-WsZP88O6.js +0 -266
- package/lib/vite/traceViewer/defaultSettingsView.ConWv5KN.css +0 -1
- package/lib/vite/traceViewer/index.C4Y3Aw8n.css +0 -1
- package/lib/vite/traceViewer/index.C8xAeo93.js +0 -2
- package/lib/vite/traceViewer/uiMode.BltraIJB.js +0 -5
- /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
- /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var browserBackend_exports = {};
|
|
20
|
+
__export(browserBackend_exports, {
|
|
21
|
+
BrowserBackend: () => BrowserBackend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(browserBackend_exports);
|
|
24
|
+
var import_context = require("./context");
|
|
25
|
+
var import_response = require("./response");
|
|
26
|
+
var import_sessionLog = require("./sessionLog");
|
|
27
|
+
var import_utilsBundle = require("../../utilsBundle");
|
|
28
|
+
class BrowserBackend {
|
|
29
|
+
constructor(config, browserContext, tools) {
|
|
30
|
+
this._config = config;
|
|
31
|
+
this._tools = tools;
|
|
32
|
+
this.browserContext = browserContext;
|
|
33
|
+
}
|
|
34
|
+
async initialize(clientInfo) {
|
|
35
|
+
this._sessionLog = this._config.saveSession ? await import_sessionLog.SessionLog.create(this._config, clientInfo.cwd) : void 0;
|
|
36
|
+
this._context = new import_context.Context(this.browserContext, {
|
|
37
|
+
config: this._config,
|
|
38
|
+
sessionLog: this._sessionLog,
|
|
39
|
+
cwd: clientInfo.cwd
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async dispose() {
|
|
43
|
+
await this._context?.dispose().catch((e) => (0, import_utilsBundle.debug)("pw:tools:error")(e));
|
|
44
|
+
}
|
|
45
|
+
async callTool(name, rawArguments = {}) {
|
|
46
|
+
const tool = this._tools.find((tool2) => tool2.schema.name === name);
|
|
47
|
+
if (!tool) {
|
|
48
|
+
return {
|
|
49
|
+
content: [{ type: "text", text: `### Error
|
|
50
|
+
Tool "${name}" not found` }],
|
|
51
|
+
isError: true
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const parsedArguments = tool.schema.inputSchema.parse(rawArguments);
|
|
55
|
+
const cwd = rawArguments._meta?.cwd;
|
|
56
|
+
const context = this._context;
|
|
57
|
+
const response = new import_response.Response(context, name, parsedArguments, cwd);
|
|
58
|
+
context.setRunningTool(name);
|
|
59
|
+
let responseObject;
|
|
60
|
+
try {
|
|
61
|
+
await tool.handle(context, parsedArguments, response);
|
|
62
|
+
responseObject = await response.serialize();
|
|
63
|
+
this._sessionLog?.logResponse(name, parsedArguments, responseObject);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: "text", text: `### Error
|
|
67
|
+
${String(error)}` }],
|
|
68
|
+
isError: true
|
|
69
|
+
};
|
|
70
|
+
} finally {
|
|
71
|
+
context.setRunningTool(void 0);
|
|
72
|
+
}
|
|
73
|
+
return responseObject;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
BrowserBackend
|
|
79
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var common_exports = {};
|
|
20
|
+
__export(common_exports, {
|
|
21
|
+
default: () => common_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(common_exports);
|
|
24
|
+
var import_zodBundle = require("../../zodBundle");
|
|
25
|
+
var import_tool = require("./tool");
|
|
26
|
+
var import_response = require("./response");
|
|
27
|
+
const close = (0, import_tool.defineTool)({
|
|
28
|
+
capability: "core",
|
|
29
|
+
schema: {
|
|
30
|
+
name: "browser_close",
|
|
31
|
+
title: "Close browser",
|
|
32
|
+
description: "Close the page",
|
|
33
|
+
inputSchema: import_zodBundle.z.object({}),
|
|
34
|
+
type: "action"
|
|
35
|
+
},
|
|
36
|
+
handle: async (context, params, response) => {
|
|
37
|
+
const result = (0, import_response.renderTabsMarkdown)([]);
|
|
38
|
+
response.addTextResult(result.join("\n"));
|
|
39
|
+
response.addCode(`await page.close()`);
|
|
40
|
+
response.setClose();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const resize = (0, import_tool.defineTabTool)({
|
|
44
|
+
capability: "core",
|
|
45
|
+
schema: {
|
|
46
|
+
name: "browser_resize",
|
|
47
|
+
title: "Resize browser window",
|
|
48
|
+
description: "Resize the browser window",
|
|
49
|
+
inputSchema: import_zodBundle.z.object({
|
|
50
|
+
width: import_zodBundle.z.number().describe("Width of the browser window"),
|
|
51
|
+
height: import_zodBundle.z.number().describe("Height of the browser window")
|
|
52
|
+
}),
|
|
53
|
+
type: "action"
|
|
54
|
+
},
|
|
55
|
+
handle: async (tab, params, response) => {
|
|
56
|
+
response.addCode(`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`);
|
|
57
|
+
await tab.page.setViewportSize({ width: params.width, height: params.height });
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var common_default = [
|
|
61
|
+
close,
|
|
62
|
+
resize
|
|
63
|
+
];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var config_exports = {};
|
|
20
|
+
__export(config_exports, {
|
|
21
|
+
default: () => config_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(config_exports);
|
|
24
|
+
var import_zodBundle = require("../../zodBundle");
|
|
25
|
+
var import_tool = require("./tool");
|
|
26
|
+
const configShow = (0, import_tool.defineTool)({
|
|
27
|
+
capability: "config",
|
|
28
|
+
schema: {
|
|
29
|
+
name: "browser_get_config",
|
|
30
|
+
title: "Get config",
|
|
31
|
+
description: "Get the final resolved config after merging CLI options, environment variables and config file.",
|
|
32
|
+
inputSchema: import_zodBundle.z.object({}),
|
|
33
|
+
type: "readOnly"
|
|
34
|
+
},
|
|
35
|
+
handle: async (context, params, response) => {
|
|
36
|
+
response.addTextResult(JSON.stringify(context.config, null, 2));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
var config_default = [
|
|
40
|
+
configShow
|
|
41
|
+
];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var console_exports = {};
|
|
20
|
+
__export(console_exports, {
|
|
21
|
+
default: () => console_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(console_exports);
|
|
24
|
+
var import_zodBundle = require("../../zodBundle");
|
|
25
|
+
var import_tool = require("./tool");
|
|
26
|
+
const console = (0, import_tool.defineTabTool)({
|
|
27
|
+
capability: "core",
|
|
28
|
+
schema: {
|
|
29
|
+
name: "browser_console_messages",
|
|
30
|
+
title: "Get console messages",
|
|
31
|
+
description: "Returns all console messages",
|
|
32
|
+
inputSchema: import_zodBundle.z.object({
|
|
33
|
+
level: import_zodBundle.z.enum(["error", "warning", "info", "debug"]).default("info").describe('Level of the console messages to return. Each level includes the messages of more severe levels. Defaults to "info".'),
|
|
34
|
+
all: import_zodBundle.z.boolean().optional().describe("Return all console messages since the beginning of the session, not just since the last navigation. Defaults to false."),
|
|
35
|
+
filename: import_zodBundle.z.string().optional().describe("Filename to save the console messages to. If not provided, messages are returned as text.")
|
|
36
|
+
}),
|
|
37
|
+
type: "readOnly"
|
|
38
|
+
},
|
|
39
|
+
handle: async (tab, params, response) => {
|
|
40
|
+
const count = await tab.consoleMessageCount();
|
|
41
|
+
const header = [`Total messages: ${count.total} (Errors: ${count.errors}, Warnings: ${count.warnings})`];
|
|
42
|
+
const messages = await tab.consoleMessages(params.level, params.all);
|
|
43
|
+
if (messages.length !== count.total)
|
|
44
|
+
header.push(`Returning ${messages.length} messages for level "${params.level}"`);
|
|
45
|
+
const text = [...header, "", ...messages.map((message) => message.toString())].join("\n");
|
|
46
|
+
await response.addResult("Console", text, { prefix: "console", ext: "log", suggestedFilename: params.filename });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const consoleClear = (0, import_tool.defineTabTool)({
|
|
50
|
+
capability: "core",
|
|
51
|
+
skillOnly: true,
|
|
52
|
+
schema: {
|
|
53
|
+
name: "browser_console_clear",
|
|
54
|
+
title: "Clear console messages",
|
|
55
|
+
description: "Clear all console messages",
|
|
56
|
+
inputSchema: import_zodBundle.z.object({}),
|
|
57
|
+
type: "readOnly"
|
|
58
|
+
},
|
|
59
|
+
handle: async (tab) => {
|
|
60
|
+
await tab.clearConsoleMessages();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
var console_default = [
|
|
64
|
+
console,
|
|
65
|
+
consoleClear
|
|
66
|
+
];
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var context_exports = {};
|
|
30
|
+
__export(context_exports, {
|
|
31
|
+
Context: () => Context,
|
|
32
|
+
outputDir: () => outputDir,
|
|
33
|
+
outputFile: () => outputFile,
|
|
34
|
+
workspaceFile: () => workspaceFile
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(context_exports);
|
|
37
|
+
var import_fs = __toESM(require("fs"));
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var import_utilsBundle = require("../../utilsBundle");
|
|
40
|
+
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
|
41
|
+
var import__ = require("../../..");
|
|
42
|
+
var import_tab = require("./tab");
|
|
43
|
+
var import_disposable = require("../../server/utils/disposable");
|
|
44
|
+
var import_eventsHelper = require("../../server/utils/eventsHelper");
|
|
45
|
+
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
|
|
46
|
+
class Context {
|
|
47
|
+
constructor(browserContext, options) {
|
|
48
|
+
this._tabs = [];
|
|
49
|
+
this._routes = [];
|
|
50
|
+
this._disposables = [];
|
|
51
|
+
this.config = options.config;
|
|
52
|
+
this.sessionLog = options.sessionLog;
|
|
53
|
+
this.options = options;
|
|
54
|
+
this._rawBrowserContext = browserContext;
|
|
55
|
+
testDebug("create context");
|
|
56
|
+
}
|
|
57
|
+
async dispose() {
|
|
58
|
+
await (0, import_disposable.disposeAll)(this._disposables);
|
|
59
|
+
for (const tab of this._tabs)
|
|
60
|
+
await tab.dispose();
|
|
61
|
+
this._tabs.length = 0;
|
|
62
|
+
this._currentTab = void 0;
|
|
63
|
+
await this.stopVideoRecording();
|
|
64
|
+
}
|
|
65
|
+
debugger() {
|
|
66
|
+
return this._rawBrowserContext.debugger;
|
|
67
|
+
}
|
|
68
|
+
tabs() {
|
|
69
|
+
return this._tabs;
|
|
70
|
+
}
|
|
71
|
+
currentTab() {
|
|
72
|
+
return this._currentTab;
|
|
73
|
+
}
|
|
74
|
+
currentTabOrDie() {
|
|
75
|
+
if (!this._currentTab)
|
|
76
|
+
throw new Error("No open pages available.");
|
|
77
|
+
return this._currentTab;
|
|
78
|
+
}
|
|
79
|
+
async newTab() {
|
|
80
|
+
const browserContext = await this.ensureBrowserContext();
|
|
81
|
+
const page = await browserContext.newPage();
|
|
82
|
+
this._currentTab = this._tabs.find((t) => t.page === page);
|
|
83
|
+
return this._currentTab;
|
|
84
|
+
}
|
|
85
|
+
async selectTab(index) {
|
|
86
|
+
const tab = this._tabs[index];
|
|
87
|
+
if (!tab)
|
|
88
|
+
throw new Error(`Tab ${index} not found`);
|
|
89
|
+
await tab.page.bringToFront();
|
|
90
|
+
this._currentTab = tab;
|
|
91
|
+
return tab;
|
|
92
|
+
}
|
|
93
|
+
async ensureTab() {
|
|
94
|
+
const browserContext = await this.ensureBrowserContext();
|
|
95
|
+
if (!this._currentTab)
|
|
96
|
+
await browserContext.newPage();
|
|
97
|
+
return this._currentTab;
|
|
98
|
+
}
|
|
99
|
+
async closeTab(index) {
|
|
100
|
+
const tab = index === void 0 ? this._currentTab : this._tabs[index];
|
|
101
|
+
if (!tab)
|
|
102
|
+
throw new Error(`Tab ${index} not found`);
|
|
103
|
+
const url = tab.page.url();
|
|
104
|
+
await tab.page.close();
|
|
105
|
+
return url;
|
|
106
|
+
}
|
|
107
|
+
async workspaceFile(fileName, perCallWorkspaceDir) {
|
|
108
|
+
return await workspaceFile(this.options, fileName, perCallWorkspaceDir);
|
|
109
|
+
}
|
|
110
|
+
async outputFile(template, options) {
|
|
111
|
+
const baseName = template.suggestedFilename || `${template.prefix}-${(template.date ?? /* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}${template.ext ? "." + template.ext : ""}`;
|
|
112
|
+
return await outputFile(this.options, baseName, options);
|
|
113
|
+
}
|
|
114
|
+
async startVideoRecording(fileName, params) {
|
|
115
|
+
if (this._video)
|
|
116
|
+
throw new Error("Video recording has already been started.");
|
|
117
|
+
this._video = { params, fileName, fileNames: [] };
|
|
118
|
+
const browserContext = await this.ensureBrowserContext();
|
|
119
|
+
for (const page of browserContext.pages())
|
|
120
|
+
await this._startPageVideo(page);
|
|
121
|
+
}
|
|
122
|
+
async stopVideoRecording() {
|
|
123
|
+
if (!this._video)
|
|
124
|
+
return [];
|
|
125
|
+
const video = this._video;
|
|
126
|
+
for (const page of this._rawBrowserContext.pages())
|
|
127
|
+
await page.screencast.stop();
|
|
128
|
+
this._video = void 0;
|
|
129
|
+
return [...video.fileNames];
|
|
130
|
+
}
|
|
131
|
+
async _startPageVideo(page) {
|
|
132
|
+
if (!this._video)
|
|
133
|
+
return;
|
|
134
|
+
const suffix = this._video.fileNames.length ? `-${this._video.fileNames.length}` : "";
|
|
135
|
+
let fileName = this._video.fileName;
|
|
136
|
+
if (fileName && suffix) {
|
|
137
|
+
const ext = import_path.default.extname(fileName);
|
|
138
|
+
fileName = import_path.default.basename(fileName, ext) + suffix + ext;
|
|
139
|
+
}
|
|
140
|
+
this._video.fileNames.push(fileName);
|
|
141
|
+
await page.screencast.start({ path: fileName, ...this._video.params });
|
|
142
|
+
}
|
|
143
|
+
_onPageCreated(page) {
|
|
144
|
+
const tab = new import_tab.Tab(this, page, (tab2) => this._onPageClosed(tab2));
|
|
145
|
+
this._tabs.push(tab);
|
|
146
|
+
if (!this._currentTab)
|
|
147
|
+
this._currentTab = tab;
|
|
148
|
+
this._startPageVideo(page).catch(() => {
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
_onPageClosed(tab) {
|
|
152
|
+
const index = this._tabs.indexOf(tab);
|
|
153
|
+
if (index === -1)
|
|
154
|
+
return;
|
|
155
|
+
this._tabs.splice(index, 1);
|
|
156
|
+
if (this._currentTab === tab)
|
|
157
|
+
this._currentTab = this._tabs[Math.min(index, this._tabs.length - 1)];
|
|
158
|
+
}
|
|
159
|
+
routes() {
|
|
160
|
+
return this._routes;
|
|
161
|
+
}
|
|
162
|
+
async addRoute(entry) {
|
|
163
|
+
const browserContext = await this.ensureBrowserContext();
|
|
164
|
+
await browserContext.route(entry.pattern, entry.handler);
|
|
165
|
+
this._routes.push(entry);
|
|
166
|
+
}
|
|
167
|
+
async removeRoute(pattern) {
|
|
168
|
+
let removed = 0;
|
|
169
|
+
const browserContext = await this.ensureBrowserContext();
|
|
170
|
+
if (pattern) {
|
|
171
|
+
const toRemove = this._routes.filter((r) => r.pattern === pattern);
|
|
172
|
+
for (const route of toRemove)
|
|
173
|
+
await browserContext.unroute(route.pattern, route.handler);
|
|
174
|
+
this._routes = this._routes.filter((r) => r.pattern !== pattern);
|
|
175
|
+
removed = toRemove.length;
|
|
176
|
+
} else {
|
|
177
|
+
for (const route of this._routes)
|
|
178
|
+
await browserContext.unroute(route.pattern, route.handler);
|
|
179
|
+
removed = this._routes.length;
|
|
180
|
+
this._routes = [];
|
|
181
|
+
}
|
|
182
|
+
return removed;
|
|
183
|
+
}
|
|
184
|
+
isRunningTool() {
|
|
185
|
+
return this._runningToolName !== void 0;
|
|
186
|
+
}
|
|
187
|
+
setRunningTool(name) {
|
|
188
|
+
this._runningToolName = name;
|
|
189
|
+
}
|
|
190
|
+
async _setupRequestInterception(context) {
|
|
191
|
+
if (this.config.network?.allowedOrigins?.length) {
|
|
192
|
+
this._disposables.push(await context.route("**", (route) => route.abort("blockedbyclient")));
|
|
193
|
+
for (const origin of this.config.network.allowedOrigins) {
|
|
194
|
+
const glob = originOrHostGlob(origin);
|
|
195
|
+
this._disposables.push(await context.route(glob, (route) => route.continue()));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (this.config.network?.blockedOrigins?.length) {
|
|
199
|
+
for (const origin of this.config.network.blockedOrigins)
|
|
200
|
+
this._disposables.push(await context.route(originOrHostGlob(origin), (route) => route.abort("blockedbyclient")));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async ensureBrowserContext() {
|
|
204
|
+
if (this._browserContextPromise)
|
|
205
|
+
return this._browserContextPromise;
|
|
206
|
+
this._browserContextPromise = this._initializeBrowserContext();
|
|
207
|
+
return this._browserContextPromise;
|
|
208
|
+
}
|
|
209
|
+
async _initializeBrowserContext() {
|
|
210
|
+
if (this.config.testIdAttribute)
|
|
211
|
+
import__.selectors.setTestIdAttribute(this.config.testIdAttribute);
|
|
212
|
+
const browserContext = this._rawBrowserContext;
|
|
213
|
+
await this._setupRequestInterception(browserContext);
|
|
214
|
+
if (this.config.saveTrace) {
|
|
215
|
+
await browserContext.tracing.start({
|
|
216
|
+
name: "trace-" + Date.now(),
|
|
217
|
+
screenshots: true,
|
|
218
|
+
snapshots: true,
|
|
219
|
+
live: true
|
|
220
|
+
});
|
|
221
|
+
this._disposables.push({
|
|
222
|
+
dispose: async () => {
|
|
223
|
+
await browserContext.tracing.stop();
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
for (const initScript of this.config.browser?.initScript || [])
|
|
228
|
+
this._disposables.push(await browserContext.addInitScript({ path: import_path.default.resolve(this.options.cwd, initScript) }));
|
|
229
|
+
for (const page of browserContext.pages())
|
|
230
|
+
this._onPageCreated(page);
|
|
231
|
+
this._disposables.push(import_eventsHelper.eventsHelper.addEventListener(browserContext, "page", (page) => this._onPageCreated(page)));
|
|
232
|
+
return browserContext;
|
|
233
|
+
}
|
|
234
|
+
checkUrlAllowed(url) {
|
|
235
|
+
if (this.config.allowUnrestrictedFileAccess)
|
|
236
|
+
return;
|
|
237
|
+
if (!URL.canParse(url))
|
|
238
|
+
return;
|
|
239
|
+
if (new URL(url).protocol === "file:")
|
|
240
|
+
throw new Error(`Access to "file:" protocol is blocked. Attempted URL: "${url}"`);
|
|
241
|
+
}
|
|
242
|
+
lookupSecret(secretName) {
|
|
243
|
+
if (!this.config.secrets?.[secretName])
|
|
244
|
+
return { value: secretName, code: (0, import_stringUtils.escapeWithQuotes)(secretName, "'") };
|
|
245
|
+
return {
|
|
246
|
+
value: this.config.secrets[secretName],
|
|
247
|
+
code: `process.env['${secretName}']`
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function originOrHostGlob(originOrHost) {
|
|
252
|
+
const wildcardPortMatch = originOrHost.match(/^(https?:\/\/[^/:]+):\*$/);
|
|
253
|
+
if (wildcardPortMatch)
|
|
254
|
+
return `${wildcardPortMatch[1]}:*/**`;
|
|
255
|
+
try {
|
|
256
|
+
const url = new URL(originOrHost);
|
|
257
|
+
if (url.origin !== "null")
|
|
258
|
+
return `${url.origin}/**`;
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
return `*://${originOrHost}/**`;
|
|
262
|
+
}
|
|
263
|
+
async function workspaceFile(options, fileName, perCallWorkspaceDir) {
|
|
264
|
+
const workspace = perCallWorkspaceDir ?? options.cwd;
|
|
265
|
+
const resolvedName = import_path.default.resolve(workspace, fileName);
|
|
266
|
+
await checkFile(options, resolvedName, { origin: "llm" });
|
|
267
|
+
return resolvedName;
|
|
268
|
+
}
|
|
269
|
+
function outputDir(options) {
|
|
270
|
+
if (options.config.outputDir)
|
|
271
|
+
return import_path.default.resolve(options.config.outputDir);
|
|
272
|
+
return import_path.default.resolve(options.cwd, options.config.skillMode ? ".playwright-cli" : ".playwright-mcp");
|
|
273
|
+
}
|
|
274
|
+
async function outputFile(options, fileName, flags) {
|
|
275
|
+
const resolvedFile = import_path.default.resolve(outputDir(options), fileName);
|
|
276
|
+
await checkFile(options, resolvedFile, flags);
|
|
277
|
+
await import_fs.default.promises.mkdir(import_path.default.dirname(resolvedFile), { recursive: true });
|
|
278
|
+
(0, import_utilsBundle.debug)("pw:mcp:file")(resolvedFile);
|
|
279
|
+
return resolvedFile;
|
|
280
|
+
}
|
|
281
|
+
async function checkFile(options, resolvedFilename, flags) {
|
|
282
|
+
if (flags.origin === "code" || options.config.allowUnrestrictedFileAccess)
|
|
283
|
+
return;
|
|
284
|
+
const output = outputDir(options);
|
|
285
|
+
const workspace = options.cwd;
|
|
286
|
+
const withinDir = (root) => resolvedFilename === root || resolvedFilename.startsWith(root + import_path.default.sep);
|
|
287
|
+
if (!withinDir(output) && !withinDir(workspace))
|
|
288
|
+
throw new Error(`File access denied: ${resolvedFilename} is outside allowed roots. Allowed roots: ${output}, ${workspace}`);
|
|
289
|
+
}
|
|
290
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
291
|
+
0 && (module.exports = {
|
|
292
|
+
Context,
|
|
293
|
+
outputDir,
|
|
294
|
+
outputFile,
|
|
295
|
+
workspaceFile
|
|
296
|
+
});
|