@one2x/playwright 1.57.0-alpha.1
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +168 -0
- package/ThirdPartyNotices.txt +6277 -0
- package/cli.js +19 -0
- package/index.d.ts +17 -0
- package/index.js +17 -0
- package/index.mjs +18 -0
- package/jsx-runtime.js +42 -0
- package/jsx-runtime.mjs +21 -0
- package/lib/agents/copilot-setup-steps.yml +34 -0
- package/lib/agents/generateAgents.js +394 -0
- package/lib/agents/generateAgents.js.map +7 -0
- package/lib/agents/playwright-test-coverage.prompt.md +31 -0
- package/lib/agents/playwright-test-generate.prompt.md +8 -0
- package/lib/agents/playwright-test-generator.agent.md +88 -0
- package/lib/agents/playwright-test-heal.prompt.md +6 -0
- package/lib/agents/playwright-test-healer.agent.md +55 -0
- package/lib/agents/playwright-test-plan.prompt.md +9 -0
- package/lib/agents/playwright-test-planner.agent.md +117 -0
- package/lib/common/config.js +280 -0
- package/lib/common/config.js.map +7 -0
- package/lib/common/configLoader.js +344 -0
- package/lib/common/configLoader.js.map +7 -0
- package/lib/common/esmLoaderHost.js +102 -0
- package/lib/common/esmLoaderHost.js.map +7 -0
- package/lib/common/expectBundle.js +52 -0
- package/lib/common/expectBundle.js.map +7 -0
- package/lib/common/expectBundleImpl.js +389 -0
- package/lib/common/expectBundleImpl.js.map +7 -0
- package/lib/common/fixtures.js +302 -0
- package/lib/common/fixtures.js.map +7 -0
- package/lib/common/globals.js +58 -0
- package/lib/common/globals.js.map +7 -0
- package/lib/common/ipc.js +60 -0
- package/lib/common/ipc.js.map +7 -0
- package/lib/common/poolBuilder.js +85 -0
- package/lib/common/poolBuilder.js.map +7 -0
- package/lib/common/process.js +104 -0
- package/lib/common/process.js.map +7 -0
- package/lib/common/suiteUtils.js +140 -0
- package/lib/common/suiteUtils.js.map +7 -0
- package/lib/common/test.js +321 -0
- package/lib/common/test.js.map +7 -0
- package/lib/common/testLoader.js +101 -0
- package/lib/common/testLoader.js.map +7 -0
- package/lib/common/testType.js +298 -0
- package/lib/common/testType.js.map +7 -0
- package/lib/common/validators.js +68 -0
- package/lib/common/validators.js.map +7 -0
- package/lib/fsWatcher.js +67 -0
- package/lib/fsWatcher.js.map +7 -0
- package/lib/index.js +682 -0
- package/lib/index.js.map +7 -0
- package/lib/internalsForTest.js +42 -0
- package/lib/internalsForTest.js.map +7 -0
- package/lib/isomorphic/events.js +77 -0
- package/lib/isomorphic/events.js.map +7 -0
- package/lib/isomorphic/folders.js +30 -0
- package/lib/isomorphic/folders.js.map +7 -0
- package/lib/isomorphic/stringInternPool.js +69 -0
- package/lib/isomorphic/stringInternPool.js.map +7 -0
- package/lib/isomorphic/teleReceiver.js +508 -0
- package/lib/isomorphic/teleReceiver.js.map +7 -0
- package/lib/isomorphic/teleSuiteUpdater.js +137 -0
- package/lib/isomorphic/teleSuiteUpdater.js.map +7 -0
- package/lib/isomorphic/testServerConnection.js +211 -0
- package/lib/isomorphic/testServerConnection.js.map +7 -0
- package/lib/isomorphic/testServerInterface.js +16 -0
- package/lib/isomorphic/testServerInterface.js.map +7 -0
- package/lib/isomorphic/testTree.js +334 -0
- package/lib/isomorphic/testTree.js.map +7 -0
- package/lib/isomorphic/types.d.js +16 -0
- package/lib/isomorphic/types.d.js.map +7 -0
- package/lib/loader/loaderMain.js +59 -0
- package/lib/loader/loaderMain.js.map +7 -0
- package/lib/matchers/expect.js +325 -0
- package/lib/matchers/expect.js.map +7 -0
- package/lib/matchers/matcherHint.js +87 -0
- package/lib/matchers/matcherHint.js.map +7 -0
- package/lib/matchers/matchers.js +366 -0
- package/lib/matchers/matchers.js.map +7 -0
- package/lib/matchers/toBeTruthy.js +73 -0
- package/lib/matchers/toBeTruthy.js.map +7 -0
- package/lib/matchers/toEqual.js +99 -0
- package/lib/matchers/toEqual.js.map +7 -0
- package/lib/matchers/toHaveURL.js +102 -0
- package/lib/matchers/toHaveURL.js.map +7 -0
- package/lib/matchers/toMatchAriaSnapshot.js +159 -0
- package/lib/matchers/toMatchAriaSnapshot.js.map +7 -0
- package/lib/matchers/toMatchSnapshot.js +341 -0
- package/lib/matchers/toMatchSnapshot.js.map +7 -0
- package/lib/matchers/toMatchText.js +99 -0
- package/lib/matchers/toMatchText.js.map +7 -0
- package/lib/mcp/browser/actions.d.js +16 -0
- package/lib/mcp/browser/actions.d.js.map +7 -0
- package/lib/mcp/browser/browserContextFactory.js +357 -0
- package/lib/mcp/browser/browserContextFactory.js.map +7 -0
- package/lib/mcp/browser/browserServerBackend.js +76 -0
- package/lib/mcp/browser/browserServerBackend.js.map +7 -0
- package/lib/mcp/browser/codegen.js +66 -0
- package/lib/mcp/browser/codegen.js.map +7 -0
- package/lib/mcp/browser/config.js +425 -0
- package/lib/mcp/browser/config.js.map +7 -0
- package/lib/mcp/browser/context.js +287 -0
- package/lib/mcp/browser/context.js.map +7 -0
- package/lib/mcp/browser/response.js +228 -0
- package/lib/mcp/browser/response.js.map +7 -0
- package/lib/mcp/browser/sessionLog.js +160 -0
- package/lib/mcp/browser/sessionLog.js.map +7 -0
- package/lib/mcp/browser/tab.js +280 -0
- package/lib/mcp/browser/tab.js.map +7 -0
- package/lib/mcp/browser/tools/actionRetry.js +40 -0
- package/lib/mcp/browser/tools/actionRetry.js.map +7 -0
- package/lib/mcp/browser/tools/common.js +63 -0
- package/lib/mcp/browser/tools/common.js.map +7 -0
- package/lib/mcp/browser/tools/console.js +44 -0
- package/lib/mcp/browser/tools/console.js.map +7 -0
- package/lib/mcp/browser/tools/dialogs.js +60 -0
- package/lib/mcp/browser/tools/dialogs.js.map +7 -0
- package/lib/mcp/browser/tools/evaluate.js +69 -0
- package/lib/mcp/browser/tools/evaluate.js.map +7 -0
- package/lib/mcp/browser/tools/files.js +58 -0
- package/lib/mcp/browser/tools/files.js.map +7 -0
- package/lib/mcp/browser/tools/form.js +79 -0
- package/lib/mcp/browser/tools/form.js.map +7 -0
- package/lib/mcp/browser/tools/install.js +69 -0
- package/lib/mcp/browser/tools/install.js.map +7 -0
- package/lib/mcp/browser/tools/keyboard.js +84 -0
- package/lib/mcp/browser/tools/keyboard.js.map +7 -0
- package/lib/mcp/browser/tools/mouse.js +107 -0
- package/lib/mcp/browser/tools/mouse.js.map +7 -0
- package/lib/mcp/browser/tools/navigate.js +62 -0
- package/lib/mcp/browser/tools/navigate.js.map +7 -0
- package/lib/mcp/browser/tools/network.js +54 -0
- package/lib/mcp/browser/tools/network.js.map +7 -0
- package/lib/mcp/browser/tools/pdf.js +59 -0
- package/lib/mcp/browser/tools/pdf.js.map +7 -0
- package/lib/mcp/browser/tools/screenshot.js +106 -0
- package/lib/mcp/browser/tools/screenshot.js.map +7 -0
- package/lib/mcp/browser/tools/snapshot.js +312 -0
- package/lib/mcp/browser/tools/snapshot.js.map +7 -0
- package/lib/mcp/browser/tools/tabs.js +67 -0
- package/lib/mcp/browser/tools/tabs.js.map +7 -0
- package/lib/mcp/browser/tools/tool.js +49 -0
- package/lib/mcp/browser/tools/tool.js.map +7 -0
- package/lib/mcp/browser/tools/tracing.js +74 -0
- package/lib/mcp/browser/tools/tracing.js.map +7 -0
- package/lib/mcp/browser/tools/utils.js +96 -0
- package/lib/mcp/browser/tools/utils.js.map +7 -0
- package/lib/mcp/browser/tools/verify.js +153 -0
- package/lib/mcp/browser/tools/verify.js.map +7 -0
- package/lib/mcp/browser/tools/wait.js +63 -0
- package/lib/mcp/browser/tools/wait.js.map +7 -0
- package/lib/mcp/browser/tools.js +80 -0
- package/lib/mcp/browser/tools.js.map +7 -0
- package/lib/mcp/browser/watchdog.js +44 -0
- package/lib/mcp/browser/watchdog.js.map +7 -0
- package/lib/mcp/config.d.js +16 -0
- package/lib/mcp/config.d.js.map +7 -0
- package/lib/mcp/extension/cdpRelay.js +351 -0
- package/lib/mcp/extension/cdpRelay.js.map +7 -0
- package/lib/mcp/extension/extensionContextFactory.js +75 -0
- package/lib/mcp/extension/extensionContextFactory.js.map +7 -0
- package/lib/mcp/extension/protocol.js +28 -0
- package/lib/mcp/extension/protocol.js.map +7 -0
- package/lib/mcp/index.js +61 -0
- package/lib/mcp/index.js.map +7 -0
- package/lib/mcp/log.js +35 -0
- package/lib/mcp/log.js.map +7 -0
- package/lib/mcp/program.js +118 -0
- package/lib/mcp/program.js.map +7 -0
- package/lib/mcp/sdk/bundle.js +81 -0
- package/lib/mcp/sdk/bundle.js.map +7 -0
- package/lib/mcp/sdk/exports.js +32 -0
- package/lib/mcp/sdk/exports.js.map +7 -0
- package/lib/mcp/sdk/http.js +276 -0
- package/lib/mcp/sdk/http.js.map +7 -0
- package/lib/mcp/sdk/inProcessTransport.js +71 -0
- package/lib/mcp/sdk/inProcessTransport.js.map +7 -0
- package/lib/mcp/sdk/mdb.js +208 -0
- package/lib/mcp/sdk/mdb.js.map +7 -0
- package/lib/mcp/sdk/proxyBackend.js +128 -0
- package/lib/mcp/sdk/proxyBackend.js.map +7 -0
- package/lib/mcp/sdk/server.js +190 -0
- package/lib/mcp/sdk/server.js.map +7 -0
- package/lib/mcp/sdk/tool.js +51 -0
- package/lib/mcp/sdk/tool.js.map +7 -0
- package/lib/mcp/test/browserBackend.js +98 -0
- package/lib/mcp/test/browserBackend.js.map +7 -0
- package/lib/mcp/test/generatorTools.js +122 -0
- package/lib/mcp/test/generatorTools.js.map +7 -0
- package/lib/mcp/test/plannerTools.js +46 -0
- package/lib/mcp/test/plannerTools.js.map +7 -0
- package/lib/mcp/test/seed.js +82 -0
- package/lib/mcp/test/seed.js.map +7 -0
- package/lib/mcp/test/streams.js +41 -0
- package/lib/mcp/test/streams.js.map +7 -0
- package/lib/mcp/test/testBackend.js +97 -0
- package/lib/mcp/test/testBackend.js.map +7 -0
- package/lib/mcp/test/testContext.js +216 -0
- package/lib/mcp/test/testContext.js.map +7 -0
- package/lib/mcp/test/testTool.js +30 -0
- package/lib/mcp/test/testTool.js.map +7 -0
- package/lib/mcp/test/testTools.js +111 -0
- package/lib/mcp/test/testTools.js.map +7 -0
- package/lib/mcpBundleImpl.js +41 -0
- package/lib/mcpBundleImpl.js.map +7 -0
- package/lib/plugins/gitCommitInfoPlugin.js +198 -0
- package/lib/plugins/gitCommitInfoPlugin.js.map +7 -0
- package/lib/plugins/index.js +28 -0
- package/lib/plugins/index.js.map +7 -0
- package/lib/plugins/webServerPlugin.js +233 -0
- package/lib/plugins/webServerPlugin.js.map +7 -0
- package/lib/program.js +412 -0
- package/lib/program.js.map +7 -0
- package/lib/reporters/base.js +609 -0
- package/lib/reporters/base.js.map +7 -0
- package/lib/reporters/blob.js +135 -0
- package/lib/reporters/blob.js.map +7 -0
- package/lib/reporters/dot.js +82 -0
- package/lib/reporters/dot.js.map +7 -0
- package/lib/reporters/empty.js +32 -0
- package/lib/reporters/empty.js.map +7 -0
- package/lib/reporters/github.js +128 -0
- package/lib/reporters/github.js.map +7 -0
- package/lib/reporters/html.js +623 -0
- package/lib/reporters/html.js.map +7 -0
- package/lib/reporters/internalReporter.js +130 -0
- package/lib/reporters/internalReporter.js.map +7 -0
- package/lib/reporters/json.js +254 -0
- package/lib/reporters/json.js.map +7 -0
- package/lib/reporters/junit.js +232 -0
- package/lib/reporters/junit.js.map +7 -0
- package/lib/reporters/line.js +113 -0
- package/lib/reporters/line.js.map +7 -0
- package/lib/reporters/list.js +231 -0
- package/lib/reporters/list.js.map +7 -0
- package/lib/reporters/listModeReporter.js +69 -0
- package/lib/reporters/listModeReporter.js.map +7 -0
- package/lib/reporters/markdown.js +144 -0
- package/lib/reporters/markdown.js.map +7 -0
- package/lib/reporters/merge.js +541 -0
- package/lib/reporters/merge.js.map +7 -0
- package/lib/reporters/multiplexer.js +104 -0
- package/lib/reporters/multiplexer.js.map +7 -0
- package/lib/reporters/reporterV2.js +102 -0
- package/lib/reporters/reporterV2.js.map +7 -0
- package/lib/reporters/teleEmitter.js +298 -0
- package/lib/reporters/teleEmitter.js.map +7 -0
- package/lib/reporters/versions/blobV1.js +16 -0
- package/lib/reporters/versions/blobV1.js.map +7 -0
- package/lib/runner/dispatcher.js +491 -0
- package/lib/runner/dispatcher.js.map +7 -0
- package/lib/runner/failureTracker.js +72 -0
- package/lib/runner/failureTracker.js.map +7 -0
- package/lib/runner/lastRun.js +77 -0
- package/lib/runner/lastRun.js.map +7 -0
- package/lib/runner/loadUtils.js +334 -0
- package/lib/runner/loadUtils.js.map +7 -0
- package/lib/runner/loaderHost.js +89 -0
- package/lib/runner/loaderHost.js.map +7 -0
- package/lib/runner/processHost.js +161 -0
- package/lib/runner/processHost.js.map +7 -0
- package/lib/runner/projectUtils.js +241 -0
- package/lib/runner/projectUtils.js.map +7 -0
- package/lib/runner/rebase.js +189 -0
- package/lib/runner/rebase.js.map +7 -0
- package/lib/runner/reporters.js +138 -0
- package/lib/runner/reporters.js.map +7 -0
- package/lib/runner/runner.js +110 -0
- package/lib/runner/sigIntWatcher.js +96 -0
- package/lib/runner/sigIntWatcher.js.map +7 -0
- package/lib/runner/taskRunner.js +127 -0
- package/lib/runner/taskRunner.js.map +7 -0
- package/lib/runner/tasks.js +410 -0
- package/lib/runner/tasks.js.map +7 -0
- package/lib/runner/testGroups.js +117 -0
- package/lib/runner/testGroups.js.map +7 -0
- package/lib/runner/testRunner.js +390 -0
- package/lib/runner/testRunner.js.map +7 -0
- package/lib/runner/testServer.js +267 -0
- package/lib/runner/testServer.js.map +7 -0
- package/lib/runner/uiModeReporter.js +30 -0
- package/lib/runner/uiModeReporter.js.map +7 -0
- package/lib/runner/vcs.js +72 -0
- package/lib/runner/vcs.js.map +7 -0
- package/lib/runner/watchMode.js +395 -0
- package/lib/runner/watchMode.js.map +7 -0
- package/lib/runner/workerHost.js +95 -0
- package/lib/runner/workerHost.js.map +7 -0
- package/lib/third_party/pirates.js +62 -0
- package/lib/third_party/pirates.js.map +7 -0
- package/lib/third_party/tsconfig-loader.js +103 -0
- package/lib/third_party/tsconfig-loader.js.map +7 -0
- package/lib/transform/babelBundle.js +43 -0
- package/lib/transform/babelBundle.js.map +7 -0
- package/lib/transform/babelBundleImpl.js +461 -0
- package/lib/transform/babelBundleImpl.js.map +7 -0
- package/lib/transform/compilationCache.js +272 -0
- package/lib/transform/compilationCache.js.map +7 -0
- package/lib/transform/esmLoader.js +104 -0
- package/lib/transform/esmLoader.js.map +7 -0
- package/lib/transform/portTransport.js +67 -0
- package/lib/transform/portTransport.js.map +7 -0
- package/lib/transform/transform.js +293 -0
- package/lib/transform/transform.js.map +7 -0
- package/lib/util.js +403 -0
- package/lib/util.js.map +7 -0
- package/lib/utilsBundle.js +43 -0
- package/lib/utilsBundle.js.map +7 -0
- package/lib/utilsBundleImpl.js +100 -0
- package/lib/utilsBundleImpl.js.map +7 -0
- package/lib/worker/fixtureRunner.js +258 -0
- package/lib/worker/fixtureRunner.js.map +7 -0
- package/lib/worker/testInfo.js +514 -0
- package/lib/worker/testInfo.js.map +7 -0
- package/lib/worker/testTracing.js +344 -0
- package/lib/worker/testTracing.js.map +7 -0
- package/lib/worker/timeoutManager.js +174 -0
- package/lib/worker/timeoutManager.js.map +7 -0
- package/lib/worker/util.js +31 -0
- package/lib/worker/util.js.map +7 -0
- package/lib/worker/workerMain.js +520 -0
- package/lib/worker/workerMain.js.map +7 -0
- package/package.json +74 -0
- package/test.d.ts +18 -0
- package/test.js +24 -0
- package/test.mjs +33 -0
- package/types/test.d.ts +10196 -0
- package/types/testReporter.d.ts +821 -0
|
@@ -0,0 +1,160 @@
|
|
|
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 sessionLog_exports = {};
|
|
30
|
+
__export(sessionLog_exports, {
|
|
31
|
+
SessionLog: () => SessionLog
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(sessionLog_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_log = require("../log");
|
|
37
|
+
var import_config = require("./config");
|
|
38
|
+
class SessionLog {
|
|
39
|
+
constructor(sessionFolder) {
|
|
40
|
+
this._ordinal = 0;
|
|
41
|
+
this._pendingEntries = [];
|
|
42
|
+
this._sessionFileQueue = Promise.resolve();
|
|
43
|
+
this._folder = sessionFolder;
|
|
44
|
+
this._file = import_path.default.join(this._folder, "session.md");
|
|
45
|
+
}
|
|
46
|
+
static async create(config, clientInfo) {
|
|
47
|
+
const sessionFolder = await (0, import_config.outputFile)(config, clientInfo, `session-${Date.now()}`, { origin: "code", reason: "Saving session" });
|
|
48
|
+
await import_fs.default.promises.mkdir(sessionFolder, { recursive: true });
|
|
49
|
+
console.error(`Session: ${sessionFolder}`);
|
|
50
|
+
return new SessionLog(sessionFolder);
|
|
51
|
+
}
|
|
52
|
+
logResponse(response) {
|
|
53
|
+
const entry = {
|
|
54
|
+
timestamp: performance.now(),
|
|
55
|
+
toolCall: {
|
|
56
|
+
toolName: response.toolName,
|
|
57
|
+
toolArgs: response.toolArgs,
|
|
58
|
+
result: response.result(),
|
|
59
|
+
isError: response.isError()
|
|
60
|
+
},
|
|
61
|
+
code: response.code(),
|
|
62
|
+
tabSnapshot: response.tabSnapshot()
|
|
63
|
+
};
|
|
64
|
+
this._appendEntry(entry);
|
|
65
|
+
}
|
|
66
|
+
logUserAction(action, tab, code, isUpdate) {
|
|
67
|
+
code = code.trim();
|
|
68
|
+
if (isUpdate) {
|
|
69
|
+
const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
|
|
70
|
+
if (lastEntry?.userAction?.name === action.name) {
|
|
71
|
+
lastEntry.userAction = action;
|
|
72
|
+
lastEntry.code = code;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (action.name === "navigate") {
|
|
77
|
+
const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
|
|
78
|
+
if (lastEntry?.tabSnapshot?.url === action.url)
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const entry = {
|
|
82
|
+
timestamp: performance.now(),
|
|
83
|
+
userAction: action,
|
|
84
|
+
code,
|
|
85
|
+
tabSnapshot: {
|
|
86
|
+
url: tab.page.url(),
|
|
87
|
+
title: "",
|
|
88
|
+
ariaSnapshot: action.ariaSnapshot || "",
|
|
89
|
+
modalStates: [],
|
|
90
|
+
consoleMessages: [],
|
|
91
|
+
downloads: []
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
this._appendEntry(entry);
|
|
95
|
+
}
|
|
96
|
+
_appendEntry(entry) {
|
|
97
|
+
this._pendingEntries.push(entry);
|
|
98
|
+
if (this._flushEntriesTimeout)
|
|
99
|
+
clearTimeout(this._flushEntriesTimeout);
|
|
100
|
+
this._flushEntriesTimeout = setTimeout(() => this._flushEntries(), 1e3);
|
|
101
|
+
}
|
|
102
|
+
async _flushEntries() {
|
|
103
|
+
clearTimeout(this._flushEntriesTimeout);
|
|
104
|
+
const entries = this._pendingEntries;
|
|
105
|
+
this._pendingEntries = [];
|
|
106
|
+
const lines = [""];
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
const ordinal = (++this._ordinal).toString().padStart(3, "0");
|
|
109
|
+
if (entry.toolCall) {
|
|
110
|
+
lines.push(
|
|
111
|
+
`### Tool call: ${entry.toolCall.toolName}`,
|
|
112
|
+
`- Args`,
|
|
113
|
+
"```json",
|
|
114
|
+
JSON.stringify(entry.toolCall.toolArgs, null, 2),
|
|
115
|
+
"```"
|
|
116
|
+
);
|
|
117
|
+
if (entry.toolCall.result) {
|
|
118
|
+
lines.push(
|
|
119
|
+
entry.toolCall.isError ? `- Error` : `- Result`,
|
|
120
|
+
"```",
|
|
121
|
+
entry.toolCall.result,
|
|
122
|
+
"```"
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (entry.userAction) {
|
|
127
|
+
const actionData = { ...entry.userAction };
|
|
128
|
+
delete actionData.ariaSnapshot;
|
|
129
|
+
delete actionData.selector;
|
|
130
|
+
delete actionData.signals;
|
|
131
|
+
lines.push(
|
|
132
|
+
`### User action: ${entry.userAction.name}`,
|
|
133
|
+
`- Args`,
|
|
134
|
+
"```json",
|
|
135
|
+
JSON.stringify(actionData, null, 2),
|
|
136
|
+
"```"
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (entry.code) {
|
|
140
|
+
lines.push(
|
|
141
|
+
`- Code`,
|
|
142
|
+
"```js",
|
|
143
|
+
entry.code,
|
|
144
|
+
"```"
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (entry.tabSnapshot) {
|
|
148
|
+
const fileName = `${ordinal}.snapshot.yml`;
|
|
149
|
+
import_fs.default.promises.writeFile(import_path.default.join(this._folder, fileName), entry.tabSnapshot.ariaSnapshot).catch(import_log.logUnhandledError);
|
|
150
|
+
lines.push(`- Snapshot: ${fileName}`);
|
|
151
|
+
}
|
|
152
|
+
lines.push("", "");
|
|
153
|
+
}
|
|
154
|
+
this._sessionFileQueue = this._sessionFileQueue.then(() => import_fs.default.promises.appendFile(this._file, lines.join("\n")));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {
|
|
159
|
+
SessionLog
|
|
160
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mcp/browser/sessionLog.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { Response } from './response';\nimport { logUnhandledError } from '../log';\nimport { outputFile } from './config';\n\nimport type { FullConfig } from './config';\nimport type * as actions from './actions';\nimport type { Tab, TabSnapshot } from './tab';\nimport type * as mcpServer from '../sdk/server';\n\ntype LogEntry = {\n timestamp: number;\n toolCall?: {\n toolName: string;\n toolArgs: Record<string, any>;\n result: string;\n isError?: boolean;\n };\n userAction?: actions.Action;\n code: string;\n tabSnapshot?: TabSnapshot;\n};\n\nexport class SessionLog {\n private _folder: string;\n private _file: string;\n private _ordinal = 0;\n private _pendingEntries: LogEntry[] = [];\n private _sessionFileQueue = Promise.resolve();\n private _flushEntriesTimeout: NodeJS.Timeout | undefined;\n\n constructor(sessionFolder: string) {\n this._folder = sessionFolder;\n this._file = path.join(this._folder, 'session.md');\n }\n\n static async create(config: FullConfig, clientInfo: mcpServer.ClientInfo): Promise<SessionLog> {\n const sessionFolder = await outputFile(config, clientInfo, `session-${Date.now()}`, { origin: 'code', reason: 'Saving session' });\n await fs.promises.mkdir(sessionFolder, { recursive: true });\n // eslint-disable-next-line no-console\n console.error(`Session: ${sessionFolder}`);\n return new SessionLog(sessionFolder);\n }\n\n logResponse(response: Response) {\n const entry: LogEntry = {\n timestamp: performance.now(),\n toolCall: {\n toolName: response.toolName,\n toolArgs: response.toolArgs,\n result: response.result(),\n isError: response.isError(),\n },\n code: response.code(),\n tabSnapshot: response.tabSnapshot(),\n };\n this._appendEntry(entry);\n }\n\n logUserAction(action: actions.Action, tab: Tab, code: string, isUpdate: boolean) {\n code = code.trim();\n if (isUpdate) {\n const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];\n if (lastEntry?.userAction?.name === action.name) {\n lastEntry.userAction = action;\n lastEntry.code = code;\n return;\n }\n }\n if (action.name === 'navigate') {\n // Already logged at this location.\n const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];\n if (lastEntry?.tabSnapshot?.url === action.url)\n return;\n }\n const entry: LogEntry = {\n timestamp: performance.now(),\n userAction: action,\n code,\n tabSnapshot: {\n url: tab.page.url(),\n title: '',\n ariaSnapshot: action.ariaSnapshot || '',\n modalStates: [],\n consoleMessages: [],\n downloads: [],\n },\n };\n this._appendEntry(entry);\n }\n\n private _appendEntry(entry: LogEntry) {\n this._pendingEntries.push(entry);\n if (this._flushEntriesTimeout)\n clearTimeout(this._flushEntriesTimeout);\n this._flushEntriesTimeout = setTimeout(() => this._flushEntries(), 1000);\n }\n\n private async _flushEntries() {\n clearTimeout(this._flushEntriesTimeout);\n const entries = this._pendingEntries;\n this._pendingEntries = [];\n const lines: string[] = [''];\n\n for (const entry of entries) {\n const ordinal = (++this._ordinal).toString().padStart(3, '0');\n if (entry.toolCall) {\n lines.push(\n `### Tool call: ${entry.toolCall.toolName}`,\n `- Args`,\n '```json',\n JSON.stringify(entry.toolCall.toolArgs, null, 2),\n '```',\n );\n if (entry.toolCall.result) {\n lines.push(\n entry.toolCall.isError ? `- Error` : `- Result`,\n '```',\n entry.toolCall.result,\n '```',\n );\n }\n }\n\n if (entry.userAction) {\n const actionData = { ...entry.userAction } as any;\n delete actionData.ariaSnapshot;\n delete actionData.selector;\n delete actionData.signals;\n\n lines.push(\n `### User action: ${entry.userAction.name}`,\n `- Args`,\n '```json',\n JSON.stringify(actionData, null, 2),\n '```',\n );\n }\n\n if (entry.code) {\n lines.push(\n `- Code`,\n '```js',\n entry.code,\n '```');\n }\n\n if (entry.tabSnapshot) {\n const fileName = `${ordinal}.snapshot.yml`;\n fs.promises.writeFile(path.join(this._folder, fileName), entry.tabSnapshot.ariaSnapshot).catch(logUnhandledError);\n lines.push(`- Snapshot: ${fileName}`);\n }\n\n lines.push('', '');\n }\n\n this._sessionFileQueue = this._sessionFileQueue.then(() => fs.promises.appendFile(this._file, lines.join('\\n')));\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,gBAAe;AACf,kBAAiB;AAGjB,iBAAkC;AAClC,oBAA4B;AAoBrB,MAAM,WAAW;AAAA,EAQtB,YAAY,eAAuB;AALnC,SAAQ,WAAW;AACnB,SAAQ,kBAA8B,CAAC;AACvC,SAAQ,oBAAoB,QAAQ,QAAQ;AAI1C,SAAK,UAAU;AACf,SAAK,QAAQ,YAAAA,QAAK,KAAK,KAAK,SAAS,YAAY;AAAA,EACnD;AAAA,EAEA,aAAa,OAAO,QAAoB,YAAuD;AAC7F,UAAM,gBAAgB,UAAM,0BAAW,QAAQ,YAAY,WAAW,KAAK,IAAI,C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AS,QAAQ,GAAG,MAAM,YAAY,YAAY,EAAE,MAAM,4BAAiB;AAChH,cAAM,KAAK,eAAe,QAAQ,EAAE;AAAA,MACtC;AAEA,YAAM,KAAK,IAAI,EAAE;AAAA,IACnB;AAEA,SAAK,oBAAoB,KAAK,kBAAkB,KAAK,MAAM,UAAAC,QAAG,SAAS,WAAW,KAAK,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC;AAAA,EACjH;AACF;",
|
|
6
|
+
"names": ["path", "fs"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
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 tab_exports = {};
|
|
20
|
+
__export(tab_exports, {
|
|
21
|
+
Tab: () => Tab,
|
|
22
|
+
TabEvents: () => TabEvents,
|
|
23
|
+
renderModalStates: () => renderModalStates
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tab_exports);
|
|
26
|
+
var import_events = require("events");
|
|
27
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
28
|
+
var import_utils2 = require("./tools/utils");
|
|
29
|
+
var import_log = require("../log");
|
|
30
|
+
var import_dialogs = require("./tools/dialogs");
|
|
31
|
+
var import_files = require("./tools/files");
|
|
32
|
+
const TabEvents = {
|
|
33
|
+
modalState: "modalState"
|
|
34
|
+
};
|
|
35
|
+
class Tab extends import_events.EventEmitter {
|
|
36
|
+
constructor(context, page, onPageClose) {
|
|
37
|
+
super();
|
|
38
|
+
this._lastTitle = "about:blank";
|
|
39
|
+
this._consoleMessages = [];
|
|
40
|
+
this._recentConsoleMessages = [];
|
|
41
|
+
this._requests = /* @__PURE__ */ new Set();
|
|
42
|
+
this._modalStates = [];
|
|
43
|
+
this._downloads = [];
|
|
44
|
+
this.context = context;
|
|
45
|
+
this.page = page;
|
|
46
|
+
this._onPageClose = onPageClose;
|
|
47
|
+
page.on("console", (event) => this._handleConsoleMessage(messageToConsoleMessage(event)));
|
|
48
|
+
page.on("pageerror", (error) => this._handleConsoleMessage(pageErrorToConsoleMessage(error)));
|
|
49
|
+
page.on("request", (request) => this._requests.add(request));
|
|
50
|
+
page.on("close", () => this._onClose());
|
|
51
|
+
page.on("filechooser", (chooser) => {
|
|
52
|
+
this.setModalState({
|
|
53
|
+
type: "fileChooser",
|
|
54
|
+
description: "File chooser",
|
|
55
|
+
fileChooser: chooser,
|
|
56
|
+
clearedBy: import_files.uploadFile.schema.name
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
page.on("dialog", (dialog) => this._dialogShown(dialog));
|
|
60
|
+
page.on("download", (download) => {
|
|
61
|
+
void this._downloadStarted(download);
|
|
62
|
+
});
|
|
63
|
+
page.setDefaultNavigationTimeout(this.context.config.timeouts.navigation);
|
|
64
|
+
page.setDefaultTimeout(this.context.config.timeouts.action);
|
|
65
|
+
page[tabSymbol] = this;
|
|
66
|
+
this._initializedPromise = this._initialize();
|
|
67
|
+
}
|
|
68
|
+
static forPage(page) {
|
|
69
|
+
return page[tabSymbol];
|
|
70
|
+
}
|
|
71
|
+
static async collectConsoleMessages(page) {
|
|
72
|
+
const result = [];
|
|
73
|
+
const messages = await page.consoleMessages().catch(() => []);
|
|
74
|
+
for (const message of messages)
|
|
75
|
+
result.push(messageToConsoleMessage(message));
|
|
76
|
+
const errors = await page.pageErrors().catch(() => []);
|
|
77
|
+
for (const error of errors)
|
|
78
|
+
result.push(pageErrorToConsoleMessage(error));
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
async _initialize() {
|
|
82
|
+
for (const message of await Tab.collectConsoleMessages(this.page))
|
|
83
|
+
this._handleConsoleMessage(message);
|
|
84
|
+
const requests = await this.page.requests().catch(() => []);
|
|
85
|
+
for (const request of requests)
|
|
86
|
+
this._requests.add(request);
|
|
87
|
+
}
|
|
88
|
+
modalStates() {
|
|
89
|
+
return this._modalStates;
|
|
90
|
+
}
|
|
91
|
+
setModalState(modalState) {
|
|
92
|
+
this._modalStates.push(modalState);
|
|
93
|
+
this.emit(TabEvents.modalState, modalState);
|
|
94
|
+
}
|
|
95
|
+
clearModalState(modalState) {
|
|
96
|
+
this._modalStates = this._modalStates.filter((state) => state !== modalState);
|
|
97
|
+
}
|
|
98
|
+
modalStatesMarkdown() {
|
|
99
|
+
return renderModalStates(this.context, this.modalStates());
|
|
100
|
+
}
|
|
101
|
+
_dialogShown(dialog) {
|
|
102
|
+
this.setModalState({
|
|
103
|
+
type: "dialog",
|
|
104
|
+
description: `"${dialog.type()}" dialog with message "${dialog.message()}"`,
|
|
105
|
+
dialog,
|
|
106
|
+
clearedBy: import_dialogs.handleDialog.schema.name
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async _downloadStarted(download) {
|
|
110
|
+
const entry = {
|
|
111
|
+
download,
|
|
112
|
+
finished: false,
|
|
113
|
+
outputFile: await this.context.outputFile(download.suggestedFilename(), { origin: "web", reason: "Saving download" })
|
|
114
|
+
};
|
|
115
|
+
this._downloads.push(entry);
|
|
116
|
+
await download.saveAs(entry.outputFile);
|
|
117
|
+
entry.finished = true;
|
|
118
|
+
}
|
|
119
|
+
_clearCollectedArtifacts() {
|
|
120
|
+
this._consoleMessages.length = 0;
|
|
121
|
+
this._recentConsoleMessages.length = 0;
|
|
122
|
+
this._requests.clear();
|
|
123
|
+
}
|
|
124
|
+
_handleConsoleMessage(message) {
|
|
125
|
+
this._consoleMessages.push(message);
|
|
126
|
+
this._recentConsoleMessages.push(message);
|
|
127
|
+
}
|
|
128
|
+
_onClose() {
|
|
129
|
+
this._clearCollectedArtifacts();
|
|
130
|
+
this._onPageClose(this);
|
|
131
|
+
}
|
|
132
|
+
async updateTitle() {
|
|
133
|
+
await this._raceAgainstModalStates(async () => {
|
|
134
|
+
this._lastTitle = await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.title());
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
lastTitle() {
|
|
138
|
+
return this._lastTitle;
|
|
139
|
+
}
|
|
140
|
+
isCurrentTab() {
|
|
141
|
+
return this === this.context.currentTab();
|
|
142
|
+
}
|
|
143
|
+
async waitForLoadState(state, options) {
|
|
144
|
+
await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForLoadState(state, options).catch(import_log.logUnhandledError));
|
|
145
|
+
}
|
|
146
|
+
async navigate(url) {
|
|
147
|
+
this._clearCollectedArtifacts();
|
|
148
|
+
const downloadEvent = (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForEvent("download").catch(import_log.logUnhandledError));
|
|
149
|
+
try {
|
|
150
|
+
await this.page.goto(url, { waitUntil: "domcontentloaded" });
|
|
151
|
+
} catch (_e) {
|
|
152
|
+
const e = _e;
|
|
153
|
+
const mightBeDownload = e.message.includes("net::ERR_ABORTED") || e.message.includes("Download is starting");
|
|
154
|
+
if (!mightBeDownload)
|
|
155
|
+
throw e;
|
|
156
|
+
const download = await Promise.race([
|
|
157
|
+
downloadEvent,
|
|
158
|
+
new Promise((resolve) => setTimeout(resolve, 3e3))
|
|
159
|
+
]);
|
|
160
|
+
if (!download)
|
|
161
|
+
throw e;
|
|
162
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
await this.waitForLoadState("load", { timeout: 5e3 });
|
|
166
|
+
}
|
|
167
|
+
async consoleMessages(type) {
|
|
168
|
+
await this._initializedPromise;
|
|
169
|
+
return this._consoleMessages.filter((message) => type ? message.type === type : true);
|
|
170
|
+
}
|
|
171
|
+
async requests() {
|
|
172
|
+
await this._initializedPromise;
|
|
173
|
+
return this._requests;
|
|
174
|
+
}
|
|
175
|
+
async captureSnapshot(mode) {
|
|
176
|
+
let tabSnapshot;
|
|
177
|
+
const modalStates = await this._raceAgainstModalStates(async () => {
|
|
178
|
+
const snapshot = await this.page._snapshotForAI({ mode, track: "response" });
|
|
179
|
+
tabSnapshot = {
|
|
180
|
+
url: this.page.url(),
|
|
181
|
+
title: await this.page.title(),
|
|
182
|
+
ariaSnapshot: snapshot,
|
|
183
|
+
modalStates: [],
|
|
184
|
+
consoleMessages: [],
|
|
185
|
+
downloads: this._downloads
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
if (tabSnapshot) {
|
|
189
|
+
tabSnapshot.consoleMessages = this._recentConsoleMessages;
|
|
190
|
+
this._recentConsoleMessages = [];
|
|
191
|
+
}
|
|
192
|
+
return tabSnapshot ?? {
|
|
193
|
+
url: this.page.url(),
|
|
194
|
+
title: "",
|
|
195
|
+
ariaSnapshot: "",
|
|
196
|
+
modalStates,
|
|
197
|
+
consoleMessages: [],
|
|
198
|
+
downloads: []
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
_javaScriptBlocked() {
|
|
202
|
+
return this._modalStates.some((state) => state.type === "dialog");
|
|
203
|
+
}
|
|
204
|
+
async _raceAgainstModalStates(action) {
|
|
205
|
+
if (this.modalStates().length)
|
|
206
|
+
return this.modalStates();
|
|
207
|
+
const promise = new import_utils.ManualPromise();
|
|
208
|
+
const listener = (modalState) => promise.resolve([modalState]);
|
|
209
|
+
this.once(TabEvents.modalState, listener);
|
|
210
|
+
return await Promise.race([
|
|
211
|
+
action().then(() => {
|
|
212
|
+
this.off(TabEvents.modalState, listener);
|
|
213
|
+
return [];
|
|
214
|
+
}),
|
|
215
|
+
promise
|
|
216
|
+
]);
|
|
217
|
+
}
|
|
218
|
+
async waitForCompletion(callback) {
|
|
219
|
+
await this._raceAgainstModalStates(() => (0, import_utils2.waitForCompletion)(this, callback));
|
|
220
|
+
}
|
|
221
|
+
async refLocator(params) {
|
|
222
|
+
return (await this.refLocators([params]))[0];
|
|
223
|
+
}
|
|
224
|
+
async refLocators(params) {
|
|
225
|
+
return Promise.all(params.map(async (param) => {
|
|
226
|
+
try {
|
|
227
|
+
const locator = this.page.locator(`aria-ref=${param.ref}`).describe(param.element);
|
|
228
|
+
const { resolvedSelector } = await locator._resolveSelector();
|
|
229
|
+
return { locator, resolved: (0, import_utils.asLocator)("javascript", resolvedSelector) };
|
|
230
|
+
} catch (e) {
|
|
231
|
+
throw new Error(`Ref ${param.ref} not found in the current page snapshot. Try capturing new snapshot.`);
|
|
232
|
+
}
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
async waitForTimeout(time) {
|
|
236
|
+
if (this._javaScriptBlocked()) {
|
|
237
|
+
await new Promise((f) => setTimeout(f, time));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => {
|
|
241
|
+
return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3)));
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function messageToConsoleMessage(message) {
|
|
246
|
+
return {
|
|
247
|
+
type: message.type(),
|
|
248
|
+
text: message.text(),
|
|
249
|
+
toString: () => `[${message.type().toUpperCase()}] ${message.text()} @ ${message.location().url}:${message.location().lineNumber}`
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function pageErrorToConsoleMessage(errorOrValue) {
|
|
253
|
+
if (errorOrValue instanceof Error) {
|
|
254
|
+
return {
|
|
255
|
+
type: "error",
|
|
256
|
+
text: errorOrValue.message,
|
|
257
|
+
toString: () => errorOrValue.stack || errorOrValue.message
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
type: "error",
|
|
262
|
+
text: String(errorOrValue),
|
|
263
|
+
toString: () => String(errorOrValue)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function renderModalStates(context, modalStates) {
|
|
267
|
+
const result = ["### Modal state"];
|
|
268
|
+
if (modalStates.length === 0)
|
|
269
|
+
result.push("- There is no modal state present");
|
|
270
|
+
for (const state of modalStates)
|
|
271
|
+
result.push(`- [${state.description}]: can be handled by the "${state.clearedBy}" tool`);
|
|
272
|
+
return result;
|
|
273
|
+
}
|
|
274
|
+
const tabSymbol = Symbol("tabSymbol");
|
|
275
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
276
|
+
0 && (module.exports = {
|
|
277
|
+
Tab,
|
|
278
|
+
TabEvents,
|
|
279
|
+
renderModalStates
|
|
280
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mcp/browser/tab.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventEmitter } from 'events';\nimport * as playwright from 'playwright-core';\nimport { asLocator, ManualPromise } from 'playwright-core/lib/utils';\n\nimport { callOnPageNoTrace, waitForCompletion } from './tools/utils';\nimport { logUnhandledError } from '../log';\nimport { ModalState } from './tools/tool';\nimport { handleDialog } from './tools/dialogs';\nimport { uploadFile } from './tools/files';\n\nimport type { Context } from './context';\nimport type { Page } from '../../../../playwright-core/src/client/page';\nimport type { Locator } from '../../../../playwright-core/src/client/locator';\n\nexport const TabEvents = {\n modalState: 'modalState'\n};\n\nexport type TabEventsInterface = {\n [TabEvents.modalState]: [modalState: ModalState];\n};\n\nexport type TabSnapshot = {\n url: string;\n title: string;\n ariaSnapshot: string;\n modalStates: ModalState[];\n consoleMessages: ConsoleMessage[];\n downloads: { download: playwright.Download, finished: boolean, outputFile: string }[];\n};\n\nexport class Tab extends EventEmitter<TabEventsInterface> {\n readonly context: Context;\n readonly page: Page;\n private _lastTitle = 'about:blank';\n private _consoleMessages: ConsoleMessage[] = [];\n private _recentConsoleMessages: ConsoleMessage[] = [];\n private _requests: Set<playwright.Request> = new Set();\n private _onPageClose: (tab: Tab) => void;\n private _modalStates: ModalState[] = [];\n private _downloads: { download: playwright.Download, finished: boolean, outputFile: string }[] = [];\n private _initializedPromise: Promise<void>;\n\n constructor(context: Context, page: playwright.Page, onPageClose: (tab: Tab) => void) {\n super();\n this.context = context;\n this.page = page as Page;\n this._onPageClose = onPageClose;\n page.on('console', event => this._handleConsoleMessage(messageToConsoleMessage(event)));\n page.on('pageerror', error => this._handleConsoleMessage(pageErrorToConsoleMessage(error)));\n page.on('request', request => this._requests.add(request));\n page.on('close', () => this._onClose());\n page.on('filechooser', chooser => {\n this.setModalState({\n type: 'fileChooser',\n description: 'File chooser',\n fileChooser: chooser,\n clearedBy: uploadFile.schema.name,\n });\n });\n page.on('dialog', dialog => this._dialogShown(dialog));\n page.on('download', download => {\n void this._downloadStarted(download);\n });\n page.setDefaultNavigationTimeout(this.context.config.timeouts.navigation);\n page.setDefaultTimeout(this.context.config.timeouts.action);\n (page as any)[tabSymbol] = this;\n this._initializedPromise = this._initialize();\n }\n\n static forPage(page: playwright.Page): Tab | undefined {\n return (page as any)[tabSymbol];\n }\n\n static async collectConsoleMessages(page: playwright.Page): Promise<ConsoleMessage[]> {\n const result: ConsoleMessage[] = [];\n const messages = await page.consoleMessages().catch(() => []);\n for (const message of messages)\n result.push(messageToConsoleMessage(message));\n const errors = await page.pageErrors().catch(() => []);\n for (const error of errors)\n result.push(pageErrorToConsoleMessage(error));\n return result;\n }\n\n private async _initialize() {\n for (const message of await Tab.collectConsoleMessages(this.page))\n this._handleConsoleMessage(message);\n const requests = await this.page.requests().catch(() => []);\n for (const request of requests)\n this._requests.add(request);\n }\n\n modalStates(): ModalState[] {\n return this._modalStates;\n }\n\n setModalState(modalState: ModalState) {\n this._modalStates.push(modalState);\n this.emit(TabEvents.modalState, modalState);\n }\n\n clearModalState(modalState: ModalState) {\n this._modalStates = this._modalStates.filter(state => state !== modalState);\n }\n\n modalStatesMarkdown(): string[] {\n return renderModalStates(this.context, this.modalStates());\n }\n\n private _dialogShown(dialog: playwright.Dialog) {\n this.setModalState({\n type: 'dialog',\n description: `\"${dialog.type()}\" dialog with message \"${dialog.message()}\"`,\n dialog,\n clearedBy: handleDialog.schema.name\n });\n }\n\n private async _downloadStarted(download: playwright.Download) {\n const entry = {\n download,\n finished: false,\n outputFile: await this.context.outputFile(download.suggestedFilename(), { origin: 'web', reason: 'Saving download' })\n };\n this._downloads.push(entry);\n await download.saveAs(entry.outputFile);\n entry.finished = true;\n }\n\n private _clearCollectedArtifacts() {\n this._consoleMessages.length = 0;\n this._recentConsoleMessages.length = 0;\n this._requests.clear();\n }\n\n private _handleConsoleMessage(message: ConsoleMessage) {\n this._consoleMessages.push(message);\n this._recentConsoleMessages.push(message);\n }\n\n private _onClose() {\n this._clearCollectedArtifacts();\n this._onPageClose(this);\n }\n\n async updateTitle() {\n await this._raceAgainstModalStates(async () => {\n this._lastTitle = await callOnPageNoTrace(this.page, page => page.title());\n });\n }\n\n lastTitle(): string {\n return this._lastTitle;\n }\n\n isCurrentTab(): boolean {\n return this === this.context.currentTab();\n }\n\n async waitForLoadState(state: 'load', options?: { timeout?: number }): Promise<void> {\n await callOnPageNoTrace(this.page, page => page.waitForLoadState(state, options).catch(logUnhandledError));\n }\n\n async navigate(url: string) {\n this._clearCollectedArtifacts();\n\n const downloadEvent = callOnPageNoTrace(this.page, page => page.waitForEvent('download').catch(logUnhandledError));\n try {\n await this.page.goto(url, { waitUntil: 'domcontentloaded' });\n } catch (_e: unknown) {\n const e = _e as Error;\n const mightBeDownload =\n e.message.includes('net::ERR_ABORTED') // chromium\n || e.message.includes('Download is starting'); // firefox + webkit\n if (!mightBeDownload)\n throw e;\n // on chromium, the download event is fired *after* page.goto rejects, so we wait a lil bit\n const download = await Promise.race([\n downloadEvent,\n new Promise(resolve => setTimeout(resolve, 3000)),\n ]);\n if (!download)\n throw e;\n // Make sure other \"download\" listeners are notified first.\n await new Promise(resolve => setTimeout(resolve, 500));\n return;\n }\n\n // Cap load event to 5 seconds, the page is operational at this point.\n await this.waitForLoadState('load', { timeout: 5000 });\n }\n\n async consoleMessages(type?: 'error'): Promise<ConsoleMessage[]> {\n await this._initializedPromise;\n return this._consoleMessages.filter(message => type ? message.type === type : true);\n }\n\n async requests(): Promise<Set<playwright.Request>> {\n await this._initializedPromise;\n return this._requests;\n }\n\n async captureSnapshot(mode: 'full' | 'incremental'): Promise<TabSnapshot> {\n let tabSnapshot: TabSnapshot | undefined;\n const modalStates = await this._raceAgainstModalStates(async () => {\n const snapshot = await this.page._snapshotForAI({ mode, track: 'response' });\n tabSnapshot = {\n url: this.page.url(),\n title: await this.page.title(),\n ariaSnapshot: snapshot,\n modalStates: [],\n consoleMessages: [],\n downloads: this._downloads,\n };\n });\n if (tabSnapshot) {\n // Assign console message late so that we did not lose any to modal state.\n tabSnapshot.consoleMessages = this._recentConsoleMessages;\n this._recentConsoleMessages = [];\n }\n return tabSnapshot ?? {\n url: this.page.url(),\n title: '',\n ariaSnapshot: '',\n modalStates,\n consoleMessages: [],\n downloads: [],\n };\n }\n\n private _javaScriptBlocked(): boolean {\n return this._modalStates.some(state => state.type === 'dialog');\n }\n\n private async _raceAgainstModalStates(action: () => Promise<void>): Promise<ModalState[]> {\n if (this.modalStates().length)\n return this.modalStates();\n\n const promise = new ManualPromise<ModalState[]>();\n const listener = (modalState: ModalState) => promise.resolve([modalState]);\n this.once(TabEvents.modalState, listener);\n\n return await Promise.race([\n action().then(() => {\n this.off(TabEvents.modalState, listener);\n return [];\n }),\n promise,\n ]);\n }\n\n async waitForCompletion(callback: () => Promise<void>) {\n await this._raceAgainstModalStates(() => waitForCompletion(this, callback));\n }\n\n async refLocator(params: { element: string, ref: string }): Promise<{ locator: Locator, resolved: string }> {\n return (await this.refLocators([params]))[0];\n }\n\n async refLocators(params: { element: string, ref: string }[]): Promise<{ locator: Locator, resolved: string }[]> {\n return Promise.all(params.map(async param => {\n try {\n const locator = this.page.locator(`aria-ref=${param.ref}`).describe(param.element) as Locator;\n const { resolvedSelector } = await locator._resolveSelector();\n return { locator, resolved: asLocator('javascript', resolvedSelector) };\n } catch (e) {\n throw new Error(`Ref ${param.ref} not found in the current page snapshot. Try capturing new snapshot.`);\n }\n }));\n }\n\n async waitForTimeout(time: number) {\n if (this._javaScriptBlocked()) {\n await new Promise(f => setTimeout(f, time));\n return;\n }\n\n await callOnPageNoTrace(this.page, page => {\n return page.evaluate(() => new Promise(f => setTimeout(f, 1000)));\n });\n }\n}\n\nexport type ConsoleMessage = {\n type: ReturnType<playwright.ConsoleMessage['type']> | undefined;\n text: string;\n toString(): string;\n};\n\nfunction messageToConsoleMessage(message: playwright.ConsoleMessage): ConsoleMessage {\n return {\n type: message.type(),\n text: message.text(),\n toString: () => `[${message.type().toUpperCase()}] ${message.text()} @ ${message.location().url}:${message.location().lineNumber}`,\n };\n}\n\nfunction pageErrorToConsoleMessage(errorOrValue: Error | any): ConsoleMessage {\n if (errorOrValue instanceof Error) {\n return {\n type: 'error',\n text: errorOrValue.message,\n toString: () => errorOrValue.stack || errorOrValue.message,\n };\n }\n return {\n type: 'error',\n text: String(errorOrValue),\n toString: () => String(errorOrValue),\n };\n}\n\nexport function renderModalStates(context: Context, modalStates: ModalState[]): string[] {\n const result: string[] = ['### Modal state'];\n if (modalStates.length === 0)\n result.push('- There is no modal state present');\n for (const state of modalStates)\n result.push(`- [${state.description}]: can be handled by the \"${state.clearedBy}\" tool`);\n return result;\n}\n\nconst tabSymbol = Symbol('tabSymbol');\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAA6B;AAE7B,mBAAyC;AAEzC,IAAAA,gBAAqD;AACrD,iBAAkC;AAElC,qBAA6B;AAC7B,mBAA2B;AAMpB,MAAM,YAAY;AAAA,EACvB,YAAY;AACd;AAeO,MAAM,YAAY,2BAAiC;AAAA,EAYxD,YAAY,SAAkB,MAAuB,aAAiC;AACpF,UAAM;AAVR,SAAQ,aAAa;AACrB,SAAQ,mBAAqC,CAAC;AAC9C,SAAQ,yBAA2C,CAAC;AACpD,SAAQ,YAAqC,oBAAI,IAAI;AAErD,SAAQ,eAA6B,CAAC;AACtC,SAAQ,aAAyF,CAAC;AAKhG,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,SAAK,eAAe;AACpB,SAAK,GAAG,WAAW,WAAS,KAAK,sBAAsB,wBAAwB,KAAK,CAAC,CAAC;AACtF,SAAK,GAAG,aAAa,WAAS,KAAK,sBAAsB,0BAA0B,KAAK,CAAC,CAAC;AAC1F,SAAK,GAAG,WAAW,aAAW,KAAK,UAAU,IAAI,OAAO,CAAC;AACzD,SAAK,GAAG,SAAS,MAAM,KAAK,SAAS,CAAC;AACtC,SAAK,GAAG,eAAe,aAAW;AAChC,WAAK,cAAc;AAAA,QACjB,MAAM;AAAA,QACN,aAAa;AAAA,QACb,aAAa;AAAA,QACb,WAAW,wBAAW,OAAO;AAAA,MAC/B,CAAC;AAAA,IACH,CAAC;AACD,SAAK,GAAG,UAAU,YAAU,KAAK,aAAa,MAAM,CAAC;AACrD,SAAK,GAAG,YAAY,cAAY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
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 actionRetry_exports = {};
|
|
20
|
+
__export(actionRetry_exports, {
|
|
21
|
+
retryWithAllowIntercept: () => retryWithAllowIntercept
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(actionRetry_exports);
|
|
24
|
+
async function retryWithAllowIntercept(action, options) {
|
|
25
|
+
try {
|
|
26
|
+
await action(options);
|
|
27
|
+
return { usedAllowIntercept: false };
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (error?.message?.includes("intercepts pointer events")) {
|
|
30
|
+
const optionsWithAllowIntercept = { ...options, allowIntercept: true };
|
|
31
|
+
await action(optionsWithAllowIntercept);
|
|
32
|
+
return { usedAllowIntercept: true };
|
|
33
|
+
}
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
retryWithAllowIntercept
|
|
40
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/mcp/browser/tools/actionRetry.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Executes a locator action with automatic retry using allowIntercept option.\n *\n * First attempts the action with the provided options. If the action fails with\n * \"intercepts pointer events\" error, automatically retries with allowIntercept: true.\n *\n * @param action - Function that performs the locator action\n * @param options - Options to pass to the action\n * @returns Object indicating whether allowIntercept was used\n */\nexport async function retryWithAllowIntercept<Options extends Record<string, any>>(\n action: (opts: Options) => Promise<void>,\n options: Options\n): Promise<{ usedAllowIntercept: boolean }> {\n try {\n // First attempt without allowIntercept\n await action(options);\n return { usedAllowIntercept: false };\n } catch (error: any) {\n // Check if error is due to element being intercepted\n if (error?.message?.includes('intercepts pointer events')) {\n // Retry with allowIntercept enabled\n const optionsWithAllowIntercept = { ...options, allowIntercept: true } as Options;\n await action(optionsWithAllowIntercept);\n return { usedAllowIntercept: true };\n }\n // Re-throw other errors\n throw error;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BA,eAAsB,wBACpB,QACA,SAC0C;AAC1C,MAAI;AAEF,UAAM,OAAO,OAAO;AACpB,WAAO,EAAE,oBAAoB,MAAM;AAAA,EACrC,SAAS,OAAY;AAEnB,QAAI,OAAO,SAAS,SAAS,2BAA2B,GAAG;AAEzD,YAAM,4BAA4B,EAAE,GAAG,SAAS,gBAAgB,KAAK;AACrE,YAAM,OAAO,yBAAyB;AACtC,aAAO,EAAE,oBAAoB,KAAK;AAAA,IACpC;AAEA,UAAM;AAAA,EACR;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -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_bundle = require("../../sdk/bundle");
|
|
25
|
+
var import_tool = require("./tool");
|
|
26
|
+
const close = (0, import_tool.defineTool)({
|
|
27
|
+
capability: "core",
|
|
28
|
+
schema: {
|
|
29
|
+
name: "browser_close",
|
|
30
|
+
title: "Close browser",
|
|
31
|
+
description: "Close the page",
|
|
32
|
+
inputSchema: import_bundle.z.object({}),
|
|
33
|
+
type: "action"
|
|
34
|
+
},
|
|
35
|
+
handle: async (context, params, response) => {
|
|
36
|
+
await context.closeBrowserContext();
|
|
37
|
+
response.setIncludeTabs();
|
|
38
|
+
response.addCode(`await page.close()`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const resize = (0, import_tool.defineTabTool)({
|
|
42
|
+
capability: "core",
|
|
43
|
+
schema: {
|
|
44
|
+
name: "browser_resize",
|
|
45
|
+
title: "Resize browser window",
|
|
46
|
+
description: "Resize the browser window",
|
|
47
|
+
inputSchema: import_bundle.z.object({
|
|
48
|
+
width: import_bundle.z.number().describe("Width of the browser window"),
|
|
49
|
+
height: import_bundle.z.number().describe("Height of the browser window")
|
|
50
|
+
}),
|
|
51
|
+
type: "action"
|
|
52
|
+
},
|
|
53
|
+
handle: async (tab, params, response) => {
|
|
54
|
+
response.addCode(`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`);
|
|
55
|
+
await tab.waitForCompletion(async () => {
|
|
56
|
+
await tab.page.setViewportSize({ width: params.width, height: params.height });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var common_default = [
|
|
61
|
+
close,
|
|
62
|
+
resize
|
|
63
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/mcp/browser/tools/common.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { z } from '../../sdk/bundle';\nimport { defineTabTool, defineTool } from './tool';\n\nconst close = defineTool({\n capability: 'core',\n\n schema: {\n name: 'browser_close',\n title: 'Close browser',\n description: 'Close the page',\n inputSchema: z.object({}),\n type: 'action',\n },\n\n handle: async (context, params, response) => {\n await context.closeBrowserContext();\n response.setIncludeTabs();\n response.addCode(`await page.close()`);\n },\n});\n\nconst resize = defineTabTool({\n capability: 'core',\n schema: {\n name: 'browser_resize',\n title: 'Resize browser window',\n description: 'Resize the browser window',\n inputSchema: z.object({\n width: z.number().describe('Width of the browser window'),\n height: z.number().describe('Height of the browser window'),\n }),\n type: 'action',\n },\n\n handle: async (tab, params, response) => {\n response.addCode(`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`);\n\n await tab.waitForCompletion(async () => {\n await tab.page.setViewportSize({ width: params.width, height: params.height });\n });\n },\n});\n\nexport default [\n close,\n resize\n];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAAkB;AAClB,kBAA0C;AAE1C,MAAM,YAAQ,wBAAW;AAAA,EACvB,YAAY;AAAA,EAEZ,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IACb,aAAa,gBAAE,OAAO,CAAC,CAAC;AAAA,IACxB,MAAM;AAAA,EACR;AAAA,EAEA,QAAQ,OAAO,SAAS,QAAQ,aAAa;AAC3C,UAAM,QAAQ,oBAAoB;AAClC,aAAS,eAAe;AACxB,aAAS,QAAQ,oBAAoB;AAAA,EACvC;AACF,CAAC;AAED,MAAM,aAAS,2BAAc;AAAA,EAC3B,YAAY;AAAA,EACZ,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IACb,aAAa,gBAAE,OAAO;AAAA,MACpB,OAAO,gBAAE,OAAO,EAAE,SAAS,6BAA6B;AAAA,MACxD,QAAQ,gBAAE,OAAO,EAAE,SAAS,8BAA8B;AAAA,IAC5D,CAAC;AAAA,IACD,MAAM;AAAA,EACR;AAAA,EAEA,QAAQ,OAAO,KAAK,QAAQ,aAAa;AACvC,aAAS,QAAQ,uCAAuC,OAAO,KAAK,aAAa,OAAO,MAAM,MAAM;AAEpG,UAAM,IAAI,kBAAkB,YAAY;AACtC,YAAM,IAAI,KAAK,gBAAgB,EAAE,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC;AAAA,IAC/E,CAAC;AAAA,EACH;AACF,CAAC;AAED,IAAO,iBAAQ;AAAA,EACb;AAAA,EACA;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|