🚀 Auto-deploy: BotVPS atualizado em 02/05/2026 15:37:40
This commit is contained in:
79
node_modules/playwright-core/lib/tools/backend/browserBackend.js
generated
vendored
Normal file
79
node_modules/playwright-core/lib/tools/backend/browserBackend.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var browserBackend_exports = {};
|
||||
__export(browserBackend_exports, {
|
||||
BrowserBackend: () => BrowserBackend
|
||||
});
|
||||
module.exports = __toCommonJS(browserBackend_exports);
|
||||
var import_context = require("./context");
|
||||
var import_response = require("./response");
|
||||
var import_sessionLog = require("./sessionLog");
|
||||
var import_utilsBundle = require("../../utilsBundle");
|
||||
class BrowserBackend {
|
||||
constructor(config, browserContext, tools) {
|
||||
this._config = config;
|
||||
this._tools = tools;
|
||||
this.browserContext = browserContext;
|
||||
}
|
||||
async initialize(clientInfo) {
|
||||
this._sessionLog = this._config.saveSession ? await import_sessionLog.SessionLog.create(this._config, clientInfo.cwd) : void 0;
|
||||
this._context = new import_context.Context(this.browserContext, {
|
||||
config: this._config,
|
||||
sessionLog: this._sessionLog,
|
||||
cwd: clientInfo.cwd
|
||||
});
|
||||
}
|
||||
async dispose() {
|
||||
await this._context?.dispose().catch((e) => (0, import_utilsBundle.debug)("pw:tools:error")(e));
|
||||
}
|
||||
async callTool(name, rawArguments = {}) {
|
||||
const tool = this._tools.find((tool2) => tool2.schema.name === name);
|
||||
if (!tool) {
|
||||
return {
|
||||
content: [{ type: "text", text: `### Error
|
||||
Tool "${name}" not found` }],
|
||||
isError: true
|
||||
};
|
||||
}
|
||||
const parsedArguments = tool.schema.inputSchema.parse(rawArguments);
|
||||
const cwd = rawArguments._meta?.cwd;
|
||||
const context = this._context;
|
||||
const response = new import_response.Response(context, name, parsedArguments, cwd);
|
||||
context.setRunningTool(name);
|
||||
let responseObject;
|
||||
try {
|
||||
await tool.handle(context, parsedArguments, response);
|
||||
responseObject = await response.serialize();
|
||||
this._sessionLog?.logResponse(name, parsedArguments, responseObject);
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [{ type: "text", text: `### Error
|
||||
${String(error)}` }],
|
||||
isError: true
|
||||
};
|
||||
} finally {
|
||||
context.setRunningTool(void 0);
|
||||
}
|
||||
return responseObject;
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
BrowserBackend
|
||||
});
|
||||
63
node_modules/playwright-core/lib/tools/backend/common.js
generated
vendored
Normal file
63
node_modules/playwright-core/lib/tools/backend/common.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var common_exports = {};
|
||||
__export(common_exports, {
|
||||
default: () => common_default
|
||||
});
|
||||
module.exports = __toCommonJS(common_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
var import_response = require("./response");
|
||||
const close = (0, import_tool.defineTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_close",
|
||||
title: "Close browser",
|
||||
description: "Close the page",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const result = (0, import_response.renderTabsMarkdown)([]);
|
||||
response.addTextResult(result.join("\n"));
|
||||
response.addCode(`await page.close()`);
|
||||
response.setClose();
|
||||
}
|
||||
});
|
||||
const resize = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_resize",
|
||||
title: "Resize browser window",
|
||||
description: "Resize the browser window",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
width: import_zodBundle.z.number().describe("Width of the browser window"),
|
||||
height: import_zodBundle.z.number().describe("Height of the browser window")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.addCode(`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`);
|
||||
await tab.page.setViewportSize({ width: params.width, height: params.height });
|
||||
}
|
||||
});
|
||||
var common_default = [
|
||||
close,
|
||||
resize
|
||||
];
|
||||
41
node_modules/playwright-core/lib/tools/backend/config.js
generated
vendored
Normal file
41
node_modules/playwright-core/lib/tools/backend/config.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var config_exports = {};
|
||||
__export(config_exports, {
|
||||
default: () => config_default
|
||||
});
|
||||
module.exports = __toCommonJS(config_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const configShow = (0, import_tool.defineTool)({
|
||||
capability: "config",
|
||||
schema: {
|
||||
name: "browser_get_config",
|
||||
title: "Get config",
|
||||
description: "Get the final resolved config after merging CLI options, environment variables and config file.",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
response.addTextResult(JSON.stringify(context.config, null, 2));
|
||||
}
|
||||
});
|
||||
var config_default = [
|
||||
configShow
|
||||
];
|
||||
66
node_modules/playwright-core/lib/tools/backend/console.js
generated
vendored
Normal file
66
node_modules/playwright-core/lib/tools/backend/console.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var console_exports = {};
|
||||
__export(console_exports, {
|
||||
default: () => console_default
|
||||
});
|
||||
module.exports = __toCommonJS(console_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const console = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_console_messages",
|
||||
title: "Get console messages",
|
||||
description: "Returns all console messages",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
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".'),
|
||||
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."),
|
||||
filename: import_zodBundle.z.string().optional().describe("Filename to save the console messages to. If not provided, messages are returned as text.")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const count = await tab.consoleMessageCount();
|
||||
const header = [`Total messages: ${count.total} (Errors: ${count.errors}, Warnings: ${count.warnings})`];
|
||||
const messages = await tab.consoleMessages(params.level, params.all);
|
||||
if (messages.length !== count.total)
|
||||
header.push(`Returning ${messages.length} messages for level "${params.level}"`);
|
||||
const text = [...header, "", ...messages.map((message) => message.toString())].join("\n");
|
||||
await response.addResult("Console", text, { prefix: "console", ext: "log", suggestedFilename: params.filename });
|
||||
}
|
||||
});
|
||||
const consoleClear = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_console_clear",
|
||||
title: "Clear console messages",
|
||||
description: "Clear all console messages",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab) => {
|
||||
await tab.clearConsoleMessages();
|
||||
}
|
||||
});
|
||||
var console_default = [
|
||||
console,
|
||||
consoleClear
|
||||
];
|
||||
296
node_modules/playwright-core/lib/tools/backend/context.js
generated
vendored
Normal file
296
node_modules/playwright-core/lib/tools/backend/context.js
generated
vendored
Normal file
@@ -0,0 +1,296 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var context_exports = {};
|
||||
__export(context_exports, {
|
||||
Context: () => Context,
|
||||
outputDir: () => outputDir,
|
||||
outputFile: () => outputFile,
|
||||
workspaceFile: () => workspaceFile
|
||||
});
|
||||
module.exports = __toCommonJS(context_exports);
|
||||
var import_fs = __toESM(require("fs"));
|
||||
var import_path = __toESM(require("path"));
|
||||
var import_utilsBundle = require("../../utilsBundle");
|
||||
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
||||
var import__ = require("../../..");
|
||||
var import_tab = require("./tab");
|
||||
var import_disposable = require("../../server/utils/disposable");
|
||||
var import_eventsHelper = require("../../server/utils/eventsHelper");
|
||||
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
|
||||
class Context {
|
||||
constructor(browserContext, options) {
|
||||
this._tabs = [];
|
||||
this._routes = [];
|
||||
this._disposables = [];
|
||||
this.config = options.config;
|
||||
this.sessionLog = options.sessionLog;
|
||||
this.options = options;
|
||||
this._rawBrowserContext = browserContext;
|
||||
testDebug("create context");
|
||||
}
|
||||
async dispose() {
|
||||
await (0, import_disposable.disposeAll)(this._disposables);
|
||||
for (const tab of this._tabs)
|
||||
await tab.dispose();
|
||||
this._tabs.length = 0;
|
||||
this._currentTab = void 0;
|
||||
await this.stopVideoRecording();
|
||||
}
|
||||
debugger() {
|
||||
return this._rawBrowserContext.debugger;
|
||||
}
|
||||
tabs() {
|
||||
return this._tabs;
|
||||
}
|
||||
currentTab() {
|
||||
return this._currentTab;
|
||||
}
|
||||
currentTabOrDie() {
|
||||
if (!this._currentTab)
|
||||
throw new Error("No open pages available.");
|
||||
return this._currentTab;
|
||||
}
|
||||
async newTab() {
|
||||
const browserContext = await this.ensureBrowserContext();
|
||||
const page = await browserContext.newPage();
|
||||
this._currentTab = this._tabs.find((t) => t.page === page);
|
||||
return this._currentTab;
|
||||
}
|
||||
async selectTab(index) {
|
||||
const tab = this._tabs[index];
|
||||
if (!tab)
|
||||
throw new Error(`Tab ${index} not found`);
|
||||
await tab.page.bringToFront();
|
||||
this._currentTab = tab;
|
||||
return tab;
|
||||
}
|
||||
async ensureTab() {
|
||||
const browserContext = await this.ensureBrowserContext();
|
||||
if (!this._currentTab)
|
||||
await browserContext.newPage();
|
||||
return this._currentTab;
|
||||
}
|
||||
async closeTab(index) {
|
||||
const tab = index === void 0 ? this._currentTab : this._tabs[index];
|
||||
if (!tab)
|
||||
throw new Error(`Tab ${index} not found`);
|
||||
const url = tab.page.url();
|
||||
await tab.page.close();
|
||||
return url;
|
||||
}
|
||||
async workspaceFile(fileName, perCallWorkspaceDir) {
|
||||
return await workspaceFile(this.options, fileName, perCallWorkspaceDir);
|
||||
}
|
||||
async outputFile(template, options) {
|
||||
const baseName = template.suggestedFilename || `${template.prefix}-${(template.date ?? /* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}${template.ext ? "." + template.ext : ""}`;
|
||||
return await outputFile(this.options, baseName, options);
|
||||
}
|
||||
async startVideoRecording(fileName, params) {
|
||||
if (this._video)
|
||||
throw new Error("Video recording has already been started.");
|
||||
this._video = { params, fileName, fileNames: [] };
|
||||
const browserContext = await this.ensureBrowserContext();
|
||||
for (const page of browserContext.pages())
|
||||
await this._startPageVideo(page);
|
||||
}
|
||||
async stopVideoRecording() {
|
||||
if (!this._video)
|
||||
return [];
|
||||
const video = this._video;
|
||||
for (const page of this._rawBrowserContext.pages())
|
||||
await page.screencast.stop();
|
||||
this._video = void 0;
|
||||
return [...video.fileNames];
|
||||
}
|
||||
async _startPageVideo(page) {
|
||||
if (!this._video)
|
||||
return;
|
||||
const suffix = this._video.fileNames.length ? `-${this._video.fileNames.length}` : "";
|
||||
let fileName = this._video.fileName;
|
||||
if (fileName && suffix) {
|
||||
const ext = import_path.default.extname(fileName);
|
||||
fileName = import_path.default.basename(fileName, ext) + suffix + ext;
|
||||
}
|
||||
this._video.fileNames.push(fileName);
|
||||
await page.screencast.start({ path: fileName, ...this._video.params });
|
||||
}
|
||||
_onPageCreated(page) {
|
||||
const tab = new import_tab.Tab(this, page, (tab2) => this._onPageClosed(tab2));
|
||||
this._tabs.push(tab);
|
||||
if (!this._currentTab)
|
||||
this._currentTab = tab;
|
||||
this._startPageVideo(page).catch(() => {
|
||||
});
|
||||
}
|
||||
_onPageClosed(tab) {
|
||||
const index = this._tabs.indexOf(tab);
|
||||
if (index === -1)
|
||||
return;
|
||||
this._tabs.splice(index, 1);
|
||||
if (this._currentTab === tab)
|
||||
this._currentTab = this._tabs[Math.min(index, this._tabs.length - 1)];
|
||||
}
|
||||
routes() {
|
||||
return this._routes;
|
||||
}
|
||||
async addRoute(entry) {
|
||||
const browserContext = await this.ensureBrowserContext();
|
||||
await browserContext.route(entry.pattern, entry.handler);
|
||||
this._routes.push(entry);
|
||||
}
|
||||
async removeRoute(pattern) {
|
||||
let removed = 0;
|
||||
const browserContext = await this.ensureBrowserContext();
|
||||
if (pattern) {
|
||||
const toRemove = this._routes.filter((r) => r.pattern === pattern);
|
||||
for (const route of toRemove)
|
||||
await browserContext.unroute(route.pattern, route.handler);
|
||||
this._routes = this._routes.filter((r) => r.pattern !== pattern);
|
||||
removed = toRemove.length;
|
||||
} else {
|
||||
for (const route of this._routes)
|
||||
await browserContext.unroute(route.pattern, route.handler);
|
||||
removed = this._routes.length;
|
||||
this._routes = [];
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
isRunningTool() {
|
||||
return this._runningToolName !== void 0;
|
||||
}
|
||||
setRunningTool(name) {
|
||||
this._runningToolName = name;
|
||||
}
|
||||
async _setupRequestInterception(context) {
|
||||
if (this.config.network?.allowedOrigins?.length) {
|
||||
this._disposables.push(await context.route("**", (route) => route.abort("blockedbyclient")));
|
||||
for (const origin of this.config.network.allowedOrigins) {
|
||||
const glob = originOrHostGlob(origin);
|
||||
this._disposables.push(await context.route(glob, (route) => route.continue()));
|
||||
}
|
||||
}
|
||||
if (this.config.network?.blockedOrigins?.length) {
|
||||
for (const origin of this.config.network.blockedOrigins)
|
||||
this._disposables.push(await context.route(originOrHostGlob(origin), (route) => route.abort("blockedbyclient")));
|
||||
}
|
||||
}
|
||||
async ensureBrowserContext() {
|
||||
if (this._browserContextPromise)
|
||||
return this._browserContextPromise;
|
||||
this._browserContextPromise = this._initializeBrowserContext();
|
||||
return this._browserContextPromise;
|
||||
}
|
||||
async _initializeBrowserContext() {
|
||||
if (this.config.testIdAttribute)
|
||||
import__.selectors.setTestIdAttribute(this.config.testIdAttribute);
|
||||
const browserContext = this._rawBrowserContext;
|
||||
await this._setupRequestInterception(browserContext);
|
||||
if (this.config.saveTrace) {
|
||||
await browserContext.tracing.start({
|
||||
name: "trace-" + Date.now(),
|
||||
screenshots: true,
|
||||
snapshots: true,
|
||||
live: true
|
||||
});
|
||||
this._disposables.push({
|
||||
dispose: async () => {
|
||||
await browserContext.tracing.stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const initScript of this.config.browser?.initScript || [])
|
||||
this._disposables.push(await browserContext.addInitScript({ path: import_path.default.resolve(this.options.cwd, initScript) }));
|
||||
for (const page of browserContext.pages())
|
||||
this._onPageCreated(page);
|
||||
this._disposables.push(import_eventsHelper.eventsHelper.addEventListener(browserContext, "page", (page) => this._onPageCreated(page)));
|
||||
return browserContext;
|
||||
}
|
||||
checkUrlAllowed(url) {
|
||||
if (this.config.allowUnrestrictedFileAccess)
|
||||
return;
|
||||
if (!URL.canParse(url))
|
||||
return;
|
||||
if (new URL(url).protocol === "file:")
|
||||
throw new Error(`Access to "file:" protocol is blocked. Attempted URL: "${url}"`);
|
||||
}
|
||||
lookupSecret(secretName) {
|
||||
if (!this.config.secrets?.[secretName])
|
||||
return { value: secretName, code: (0, import_stringUtils.escapeWithQuotes)(secretName, "'") };
|
||||
return {
|
||||
value: this.config.secrets[secretName],
|
||||
code: `process.env['${secretName}']`
|
||||
};
|
||||
}
|
||||
}
|
||||
function originOrHostGlob(originOrHost) {
|
||||
const wildcardPortMatch = originOrHost.match(/^(https?:\/\/[^/:]+):\*$/);
|
||||
if (wildcardPortMatch)
|
||||
return `${wildcardPortMatch[1]}:*/**`;
|
||||
try {
|
||||
const url = new URL(originOrHost);
|
||||
if (url.origin !== "null")
|
||||
return `${url.origin}/**`;
|
||||
} catch {
|
||||
}
|
||||
return `*://${originOrHost}/**`;
|
||||
}
|
||||
async function workspaceFile(options, fileName, perCallWorkspaceDir) {
|
||||
const workspace = perCallWorkspaceDir ?? options.cwd;
|
||||
const resolvedName = import_path.default.resolve(workspace, fileName);
|
||||
await checkFile(options, resolvedName, { origin: "llm" });
|
||||
return resolvedName;
|
||||
}
|
||||
function outputDir(options) {
|
||||
if (options.config.outputDir)
|
||||
return import_path.default.resolve(options.config.outputDir);
|
||||
return import_path.default.resolve(options.cwd, options.config.skillMode ? ".playwright-cli" : ".playwright-mcp");
|
||||
}
|
||||
async function outputFile(options, fileName, flags) {
|
||||
const resolvedFile = import_path.default.resolve(outputDir(options), fileName);
|
||||
await checkFile(options, resolvedFile, flags);
|
||||
await import_fs.default.promises.mkdir(import_path.default.dirname(resolvedFile), { recursive: true });
|
||||
(0, import_utilsBundle.debug)("pw:mcp:file")(resolvedFile);
|
||||
return resolvedFile;
|
||||
}
|
||||
async function checkFile(options, resolvedFilename, flags) {
|
||||
if (flags.origin === "code" || options.config.allowUnrestrictedFileAccess)
|
||||
return;
|
||||
const output = outputDir(options);
|
||||
const workspace = options.cwd;
|
||||
const withinDir = (root) => resolvedFilename === root || resolvedFilename.startsWith(root + import_path.default.sep);
|
||||
if (!withinDir(output) && !withinDir(workspace))
|
||||
throw new Error(`File access denied: ${resolvedFilename} is outside allowed roots. Allowed roots: ${output}, ${workspace}`);
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
Context,
|
||||
outputDir,
|
||||
outputFile,
|
||||
workspaceFile
|
||||
});
|
||||
152
node_modules/playwright-core/lib/tools/backend/cookies.js
generated
vendored
Normal file
152
node_modules/playwright-core/lib/tools/backend/cookies.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var cookies_exports = {};
|
||||
__export(cookies_exports, {
|
||||
default: () => cookies_default
|
||||
});
|
||||
module.exports = __toCommonJS(cookies_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const cookieList = (0, import_tool.defineTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_cookie_list",
|
||||
title: "List cookies",
|
||||
description: "List all cookies (optionally filtered by domain/path)",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
domain: import_zodBundle.z.string().optional().describe("Filter cookies by domain"),
|
||||
path: import_zodBundle.z.string().optional().describe("Filter cookies by path")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
let cookies = await browserContext.cookies();
|
||||
if (params.domain)
|
||||
cookies = cookies.filter((c) => c.domain.includes(params.domain));
|
||||
if (params.path)
|
||||
cookies = cookies.filter((c) => c.path.startsWith(params.path));
|
||||
if (cookies.length === 0)
|
||||
response.addTextResult("No cookies found");
|
||||
else
|
||||
response.addTextResult(cookies.map((c) => `${c.name}=${c.value} (domain: ${c.domain}, path: ${c.path})`).join("\n"));
|
||||
response.addCode(`await page.context().cookies();`);
|
||||
}
|
||||
});
|
||||
const cookieGet = (0, import_tool.defineTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_cookie_get",
|
||||
title: "Get cookie",
|
||||
description: "Get a specific cookie by name",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
name: import_zodBundle.z.string().describe("Cookie name to get")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
const cookies = await browserContext.cookies();
|
||||
const cookie = cookies.find((c) => c.name === params.name);
|
||||
if (!cookie)
|
||||
response.addTextResult(`Cookie '${params.name}' not found`);
|
||||
else
|
||||
response.addTextResult(`${cookie.name}=${cookie.value} (domain: ${cookie.domain}, path: ${cookie.path}, httpOnly: ${cookie.httpOnly}, secure: ${cookie.secure}, sameSite: ${cookie.sameSite})`);
|
||||
response.addCode(`await page.context().cookies();`);
|
||||
}
|
||||
});
|
||||
const cookieSet = (0, import_tool.defineTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_cookie_set",
|
||||
title: "Set cookie",
|
||||
description: "Set a cookie with optional flags (domain, path, expires, httpOnly, secure, sameSite)",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
name: import_zodBundle.z.string().describe("Cookie name"),
|
||||
value: import_zodBundle.z.string().describe("Cookie value"),
|
||||
domain: import_zodBundle.z.string().optional().describe("Cookie domain"),
|
||||
path: import_zodBundle.z.string().optional().describe("Cookie path"),
|
||||
expires: import_zodBundle.z.number().optional().describe("Cookie expiration as Unix timestamp"),
|
||||
httpOnly: import_zodBundle.z.boolean().optional().describe("Whether the cookie is HTTP only"),
|
||||
secure: import_zodBundle.z.boolean().optional().describe("Whether the cookie is secure"),
|
||||
sameSite: import_zodBundle.z.enum(["Strict", "Lax", "None"]).optional().describe("Cookie SameSite attribute")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
const tab = await context.ensureTab();
|
||||
const url = new URL(tab.page.url());
|
||||
const cookie = {
|
||||
name: params.name,
|
||||
value: params.value,
|
||||
domain: params.domain || url.hostname,
|
||||
path: params.path || "/"
|
||||
};
|
||||
if (params.expires !== void 0)
|
||||
cookie.expires = params.expires;
|
||||
if (params.httpOnly !== void 0)
|
||||
cookie.httpOnly = params.httpOnly;
|
||||
if (params.secure !== void 0)
|
||||
cookie.secure = params.secure;
|
||||
if (params.sameSite !== void 0)
|
||||
cookie.sameSite = params.sameSite;
|
||||
await browserContext.addCookies([cookie]);
|
||||
response.addCode(`await page.context().addCookies([${JSON.stringify(cookie)}]);`);
|
||||
}
|
||||
});
|
||||
const cookieDelete = (0, import_tool.defineTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_cookie_delete",
|
||||
title: "Delete cookie",
|
||||
description: "Delete a specific cookie",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
name: import_zodBundle.z.string().describe("Cookie name to delete")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
await browserContext.clearCookies({ name: params.name });
|
||||
response.addCode(`await page.context().clearCookies({ name: '${params.name}' });`);
|
||||
}
|
||||
});
|
||||
const cookieClear = (0, import_tool.defineTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_cookie_clear",
|
||||
title: "Clear cookies",
|
||||
description: "Clear all cookies",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
await browserContext.clearCookies();
|
||||
response.addCode(`await page.context().clearCookies();`);
|
||||
}
|
||||
});
|
||||
var cookies_default = [
|
||||
cookieList,
|
||||
cookieGet,
|
||||
cookieSet,
|
||||
cookieDelete,
|
||||
cookieClear
|
||||
];
|
||||
69
node_modules/playwright-core/lib/tools/backend/devtools.js
generated
vendored
Normal file
69
node_modules/playwright-core/lib/tools/backend/devtools.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var devtools_exports = {};
|
||||
__export(devtools_exports, {
|
||||
default: () => devtools_default
|
||||
});
|
||||
module.exports = __toCommonJS(devtools_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const resume = (0, import_tool.defineTool)({
|
||||
capability: "devtools",
|
||||
schema: {
|
||||
name: "browser_resume",
|
||||
title: "Resume paused script execution",
|
||||
description: "Resume script execution after it was paused. When called with step set to true, execution will pause again before the next action.",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
step: import_zodBundle.z.boolean().optional().describe("When true, execution will pause again before the next action, allowing step-by-step debugging."),
|
||||
location: import_zodBundle.z.string().optional().describe('Pause execution at a specific <file>:<line>, e.g. "example.spec.ts:42".')
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
const pausedPromise = new Promise((resolve) => {
|
||||
const listener = () => {
|
||||
if (browserContext.debugger.pausedDetails()) {
|
||||
browserContext.debugger.off("pausedstatechanged", listener);
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
browserContext.debugger.on("pausedstatechanged", listener);
|
||||
});
|
||||
if (params.location) {
|
||||
const [file, lineStr] = params.location.split(":");
|
||||
let location;
|
||||
if (lineStr) {
|
||||
const line = Number(lineStr);
|
||||
if (isNaN(line))
|
||||
throw new Error(`Invalid location "${params.location}", expected format is <file>:<line>, e.g. "example.spec.ts:42"`);
|
||||
location = { file, line };
|
||||
} else {
|
||||
location = { file: params.location };
|
||||
}
|
||||
await browserContext.debugger.runTo(location);
|
||||
} else if (params.step) {
|
||||
await browserContext.debugger.next();
|
||||
} else {
|
||||
await browserContext.debugger.resume();
|
||||
}
|
||||
await pausedPromise;
|
||||
}
|
||||
});
|
||||
var devtools_default = [resume];
|
||||
59
node_modules/playwright-core/lib/tools/backend/dialogs.js
generated
vendored
Normal file
59
node_modules/playwright-core/lib/tools/backend/dialogs.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var dialogs_exports = {};
|
||||
__export(dialogs_exports, {
|
||||
default: () => dialogs_default,
|
||||
handleDialog: () => handleDialog
|
||||
});
|
||||
module.exports = __toCommonJS(dialogs_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const handleDialog = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_handle_dialog",
|
||||
title: "Handle a dialog",
|
||||
description: "Handle a dialog",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
accept: import_zodBundle.z.boolean().describe("Whether to accept the dialog."),
|
||||
promptText: import_zodBundle.z.string().optional().describe("The text of the prompt in case of a prompt dialog.")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const dialogState = tab.modalStates().find((state) => state.type === "dialog");
|
||||
if (!dialogState)
|
||||
throw new Error("No dialog visible");
|
||||
tab.clearModalState(dialogState);
|
||||
await tab.waitForCompletion(async () => {
|
||||
if (params.accept)
|
||||
await dialogState.dialog.accept(params.promptText);
|
||||
else
|
||||
await dialogState.dialog.dismiss();
|
||||
});
|
||||
},
|
||||
clearsModalState: "dialog"
|
||||
});
|
||||
var dialogs_default = [
|
||||
handleDialog
|
||||
];
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
handleDialog
|
||||
});
|
||||
64
node_modules/playwright-core/lib/tools/backend/evaluate.js
generated
vendored
Normal file
64
node_modules/playwright-core/lib/tools/backend/evaluate.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var evaluate_exports = {};
|
||||
__export(evaluate_exports, {
|
||||
default: () => evaluate_default
|
||||
});
|
||||
module.exports = __toCommonJS(evaluate_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
||||
var import_tool = require("./tool");
|
||||
const evaluateSchema = import_zodBundle.z.object({
|
||||
function: import_zodBundle.z.string().describe("() => { /* code */ } or (element) => { /* code */ } when element is provided"),
|
||||
element: import_zodBundle.z.string().optional().describe("Human-readable element description used to obtain permission to interact with the element"),
|
||||
ref: import_zodBundle.z.string().optional().describe("Exact target element reference from the page snapshot"),
|
||||
selector: import_zodBundle.z.string().optional().describe('CSS or role selector for the target element, when "ref" is not available.'),
|
||||
filename: import_zodBundle.z.string().optional().describe("Filename to save the result to. If not provided, result is returned as text.")
|
||||
});
|
||||
const evaluate = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_evaluate",
|
||||
title: "Evaluate JavaScript",
|
||||
description: "Evaluate JavaScript expression on page or element",
|
||||
inputSchema: evaluateSchema,
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
let locator;
|
||||
if (!params.function.includes("=>"))
|
||||
params.function = `() => (${params.function})`;
|
||||
if (params.ref) {
|
||||
locator = await tab.refLocator({ ref: params.ref, selector: params.selector, element: params.element || "element" });
|
||||
response.addCode(`await page.${locator.resolved}.evaluate(${(0, import_stringUtils.escapeWithQuotes)(params.function)});`);
|
||||
} else {
|
||||
response.addCode(`await page.evaluate(${(0, import_stringUtils.escapeWithQuotes)(params.function)});`);
|
||||
}
|
||||
await tab.waitForCompletion(async () => {
|
||||
const func = new Function();
|
||||
func.toString = () => params.function;
|
||||
const result = locator?.locator ? await locator?.locator.evaluate(func) : await tab.page.evaluate(func);
|
||||
const text = JSON.stringify(result, null, 2) || "undefined";
|
||||
await response.addResult("Evaluation result", text, { prefix: "result", ext: "json", suggestedFilename: params.filename });
|
||||
});
|
||||
}
|
||||
});
|
||||
var evaluate_default = [
|
||||
evaluate
|
||||
];
|
||||
60
node_modules/playwright-core/lib/tools/backend/files.js
generated
vendored
Normal file
60
node_modules/playwright-core/lib/tools/backend/files.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var files_exports = {};
|
||||
__export(files_exports, {
|
||||
default: () => files_default,
|
||||
uploadFile: () => uploadFile
|
||||
});
|
||||
module.exports = __toCommonJS(files_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const uploadFile = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_file_upload",
|
||||
title: "Upload files",
|
||||
description: "Upload one or multiple files",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
paths: import_zodBundle.z.array(import_zodBundle.z.string()).optional().describe("The absolute paths to the files to upload. Can be single file or multiple files. If omitted, file chooser is cancelled.")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.setIncludeSnapshot();
|
||||
const modalState = tab.modalStates().find((state) => state.type === "fileChooser");
|
||||
if (!modalState)
|
||||
throw new Error("No file chooser visible");
|
||||
if (params.paths)
|
||||
await Promise.all(params.paths.map((filePath) => response.resolveClientFilename(filePath)));
|
||||
response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`);
|
||||
tab.clearModalState(modalState);
|
||||
await tab.waitForCompletion(async () => {
|
||||
if (params.paths)
|
||||
await modalState.fileChooser.setFiles(params.paths);
|
||||
});
|
||||
},
|
||||
clearsModalState: "fileChooser"
|
||||
});
|
||||
var files_default = [
|
||||
uploadFile
|
||||
];
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
uploadFile
|
||||
});
|
||||
64
node_modules/playwright-core/lib/tools/backend/form.js
generated
vendored
Normal file
64
node_modules/playwright-core/lib/tools/backend/form.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var form_exports = {};
|
||||
__export(form_exports, {
|
||||
default: () => form_default
|
||||
});
|
||||
module.exports = __toCommonJS(form_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
||||
var import_tool = require("./tool");
|
||||
const fillForm = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_fill_form",
|
||||
title: "Fill form",
|
||||
description: "Fill multiple form fields",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
fields: import_zodBundle.z.array(import_zodBundle.z.object({
|
||||
name: import_zodBundle.z.string().describe("Human-readable field name"),
|
||||
type: import_zodBundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the field"),
|
||||
ref: import_zodBundle.z.string().describe("Exact target field reference from the page snapshot"),
|
||||
selector: import_zodBundle.z.string().optional().describe('CSS or role selector for the field element, when "ref" is not available. Either "selector" or "ref" is required.'),
|
||||
value: import_zodBundle.z.string().describe("Value to fill in the field. If the field is a checkbox, the value should be `true` or `false`. If the field is a combobox, the value should be the text of the option.")
|
||||
})).describe("Fields to fill in")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
for (const field of params.fields) {
|
||||
const { locator, resolved } = await tab.refLocator({ element: field.name, ref: field.ref, selector: field.selector });
|
||||
const locatorSource = `await page.${resolved}`;
|
||||
if (field.type === "textbox" || field.type === "slider") {
|
||||
const secret = tab.context.lookupSecret(field.value);
|
||||
await locator.fill(secret.value, tab.actionTimeoutOptions);
|
||||
response.addCode(`${locatorSource}.fill(${secret.code});`);
|
||||
} else if (field.type === "checkbox" || field.type === "radio") {
|
||||
await locator.setChecked(field.value === "true", tab.actionTimeoutOptions);
|
||||
response.addCode(`${locatorSource}.setChecked(${field.value});`);
|
||||
} else if (field.type === "combobox") {
|
||||
await locator.selectOption({ label: field.value }, tab.actionTimeoutOptions);
|
||||
response.addCode(`${locatorSource}.selectOption(${(0, import_stringUtils.escapeWithQuotes)(field.value)});`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
var form_default = [
|
||||
fillForm
|
||||
];
|
||||
155
node_modules/playwright-core/lib/tools/backend/keyboard.js
generated
vendored
Normal file
155
node_modules/playwright-core/lib/tools/backend/keyboard.js
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var keyboard_exports = {};
|
||||
__export(keyboard_exports, {
|
||||
default: () => keyboard_default
|
||||
});
|
||||
module.exports = __toCommonJS(keyboard_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
var import_snapshot = require("./snapshot");
|
||||
const press = (0, import_tool.defineTabTool)({
|
||||
capability: "core-input",
|
||||
schema: {
|
||||
name: "browser_press_key",
|
||||
title: "Press a key",
|
||||
description: "Press a key on the keyboard",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.addCode(`// Press ${params.key}`);
|
||||
response.addCode(`await page.keyboard.press('${params.key}');`);
|
||||
if (params.key === "Enter") {
|
||||
response.setIncludeSnapshot();
|
||||
await tab.waitForCompletion(async () => {
|
||||
await tab.page.keyboard.press("Enter");
|
||||
});
|
||||
} else {
|
||||
await tab.page.keyboard.press(params.key);
|
||||
}
|
||||
}
|
||||
});
|
||||
const pressSequentially = (0, import_tool.defineTabTool)({
|
||||
capability: "core-input",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_press_sequentially",
|
||||
title: "Type text key by key",
|
||||
description: "Type text key by key on the keyboard",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
text: import_zodBundle.z.string().describe("Text to type"),
|
||||
submit: import_zodBundle.z.boolean().optional().describe("Whether to submit entered text (press Enter after)")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.addCode(`// Press ${params.text}`);
|
||||
response.addCode(`await page.keyboard.type('${params.text}');`);
|
||||
await tab.page.keyboard.type(params.text);
|
||||
if (params.submit) {
|
||||
response.addCode(`await page.keyboard.press('Enter');`);
|
||||
response.setIncludeSnapshot();
|
||||
await tab.waitForCompletion(async () => {
|
||||
await tab.page.keyboard.press("Enter");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
const typeSchema = import_snapshot.elementSchema.extend({
|
||||
text: import_zodBundle.z.string().describe("Text to type into the element"),
|
||||
submit: import_zodBundle.z.boolean().optional().describe("Whether to submit entered text (press Enter after)"),
|
||||
slowly: import_zodBundle.z.boolean().optional().describe("Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.")
|
||||
});
|
||||
const type = (0, import_tool.defineTabTool)({
|
||||
capability: "core-input",
|
||||
schema: {
|
||||
name: "browser_type",
|
||||
title: "Type text",
|
||||
description: "Type text into editable element",
|
||||
inputSchema: typeSchema,
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const { locator, resolved } = await tab.refLocator(params);
|
||||
const secret = tab.context.lookupSecret(params.text);
|
||||
const action = async () => {
|
||||
if (params.slowly) {
|
||||
response.setIncludeSnapshot();
|
||||
response.addCode(`await page.${resolved}.pressSequentially(${secret.code});`);
|
||||
await locator.pressSequentially(secret.value, tab.actionTimeoutOptions);
|
||||
} else {
|
||||
response.addCode(`await page.${resolved}.fill(${secret.code});`);
|
||||
await locator.fill(secret.value, tab.actionTimeoutOptions);
|
||||
}
|
||||
if (params.submit) {
|
||||
response.setIncludeSnapshot();
|
||||
response.addCode(`await page.${resolved}.press('Enter');`);
|
||||
await locator.press("Enter", tab.actionTimeoutOptions);
|
||||
}
|
||||
};
|
||||
if (params.submit || params.slowly)
|
||||
await tab.waitForCompletion(action);
|
||||
else
|
||||
await action();
|
||||
}
|
||||
});
|
||||
const keydown = (0, import_tool.defineTabTool)({
|
||||
capability: "core-input",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_keydown",
|
||||
title: "Press a key down",
|
||||
description: "Press a key down on the keyboard",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.addCode(`await page.keyboard.down('${params.key}');`);
|
||||
await tab.page.keyboard.down(params.key);
|
||||
}
|
||||
});
|
||||
const keyup = (0, import_tool.defineTabTool)({
|
||||
capability: "core-input",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_keyup",
|
||||
title: "Press a key up",
|
||||
description: "Press a key up on the keyboard",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.addCode(`await page.keyboard.up('${params.key}');`);
|
||||
await tab.page.keyboard.up(params.key);
|
||||
}
|
||||
});
|
||||
var keyboard_default = [
|
||||
press,
|
||||
type,
|
||||
pressSequentially,
|
||||
keydown,
|
||||
keyup
|
||||
];
|
||||
95
node_modules/playwright-core/lib/tools/backend/logFile.js
generated
vendored
Normal file
95
node_modules/playwright-core/lib/tools/backend/logFile.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var logFile_exports = {};
|
||||
__export(logFile_exports, {
|
||||
LogFile: () => LogFile
|
||||
});
|
||||
module.exports = __toCommonJS(logFile_exports);
|
||||
var import_fs = __toESM(require("fs"));
|
||||
var import_path = __toESM(require("path"));
|
||||
var import_utilsBundle = require("../../utilsBundle");
|
||||
class LogFile {
|
||||
constructor(context, startTime, filePrefix, title) {
|
||||
this._stopped = false;
|
||||
this._line = 0;
|
||||
this._entries = 0;
|
||||
this._lastLine = 0;
|
||||
this._lastEntries = 0;
|
||||
this._writeChain = Promise.resolve();
|
||||
this._context = context;
|
||||
this._startTime = startTime;
|
||||
this._filePrefix = filePrefix;
|
||||
this._title = title;
|
||||
}
|
||||
appendLine(wallTime, text) {
|
||||
this._writeChain = this._writeChain.then(() => this._write(wallTime, text)).catch((e) => (0, import_utilsBundle.debug)("pw:tools:error")(e));
|
||||
}
|
||||
stop() {
|
||||
this._stopped = true;
|
||||
}
|
||||
async take(relativeTo) {
|
||||
const logChunk = await this._take();
|
||||
if (!logChunk)
|
||||
return void 0;
|
||||
const logFilePath = relativeTo ? import_path.default.relative(relativeTo, logChunk.file) : logChunk.file;
|
||||
const lineRange = logChunk.fromLine === logChunk.toLine ? `#L${logChunk.fromLine}` : `#L${logChunk.fromLine}-L${logChunk.toLine}`;
|
||||
return `${logFilePath}${lineRange}`;
|
||||
}
|
||||
async _take() {
|
||||
await this._writeChain;
|
||||
if (!this._file || this._entries === this._lastEntries)
|
||||
return void 0;
|
||||
const chunk = {
|
||||
type: this._title.toLowerCase(),
|
||||
file: this._file,
|
||||
fromLine: this._lastLine + 1,
|
||||
toLine: this._line,
|
||||
entryCount: this._entries - this._lastEntries
|
||||
};
|
||||
this._lastLine = this._line;
|
||||
this._lastEntries = this._entries;
|
||||
return chunk;
|
||||
}
|
||||
async _write(wallTime, text) {
|
||||
if (this._stopped)
|
||||
return;
|
||||
this._file ??= await this._context.outputFile({ prefix: this._filePrefix, ext: "log", date: new Date(this._startTime) }, { origin: "code" });
|
||||
const relativeTime = Math.round(wallTime - this._startTime);
|
||||
const logLine = `[${String(relativeTime).padStart(8, " ")}ms] ${text}
|
||||
`;
|
||||
await import_fs.default.promises.appendFile(this._file, logLine);
|
||||
const lineCount = logLine.split("\n").length - 1;
|
||||
this._line += lineCount;
|
||||
this._entries++;
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
LogFile
|
||||
});
|
||||
168
node_modules/playwright-core/lib/tools/backend/mouse.js
generated
vendored
Normal file
168
node_modules/playwright-core/lib/tools/backend/mouse.js
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var mouse_exports = {};
|
||||
__export(mouse_exports, {
|
||||
default: () => mouse_default
|
||||
});
|
||||
module.exports = __toCommonJS(mouse_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
||||
var import_tool = require("./tool");
|
||||
const mouseMove = (0, import_tool.defineTabTool)({
|
||||
capability: "vision",
|
||||
schema: {
|
||||
name: "browser_mouse_move_xy",
|
||||
title: "Move mouse",
|
||||
description: "Move mouse to a given position",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
x: import_zodBundle.z.number().describe("X coordinate"),
|
||||
y: import_zodBundle.z.number().describe("Y coordinate")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.addCode(`// Move mouse to (${params.x}, ${params.y})`);
|
||||
response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
|
||||
await tab.page.mouse.move(params.x, params.y);
|
||||
}
|
||||
});
|
||||
const mouseDown = (0, import_tool.defineTabTool)({
|
||||
capability: "vision",
|
||||
schema: {
|
||||
name: "browser_mouse_down",
|
||||
title: "Press mouse down",
|
||||
description: "Press mouse down",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
button: import_zodBundle.z.enum(["left", "right", "middle"]).optional().describe("Button to press, defaults to left")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const options = { button: params.button };
|
||||
const optionsArg = (0, import_stringUtils.formatObjectOrVoid)(options);
|
||||
response.addCode(`// Press mouse down`);
|
||||
response.addCode(`await page.mouse.down(${optionsArg});`);
|
||||
await tab.page.mouse.down(options);
|
||||
}
|
||||
});
|
||||
const mouseUp = (0, import_tool.defineTabTool)({
|
||||
capability: "vision",
|
||||
schema: {
|
||||
name: "browser_mouse_up",
|
||||
title: "Press mouse up",
|
||||
description: "Press mouse up",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
button: import_zodBundle.z.enum(["left", "right", "middle"]).optional().describe("Button to press, defaults to left")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const options = { button: params.button };
|
||||
const optionsArg = (0, import_stringUtils.formatObjectOrVoid)(options);
|
||||
response.addCode(`// Press mouse up`);
|
||||
response.addCode(`await page.mouse.up(${optionsArg});`);
|
||||
await tab.page.mouse.up(options);
|
||||
}
|
||||
});
|
||||
const mouseWheel = (0, import_tool.defineTabTool)({
|
||||
capability: "vision",
|
||||
schema: {
|
||||
name: "browser_mouse_wheel",
|
||||
title: "Scroll mouse wheel",
|
||||
description: "Scroll mouse wheel",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
deltaX: import_zodBundle.z.number().default(0).describe("X delta"),
|
||||
deltaY: import_zodBundle.z.number().default(0).describe("Y delta")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.addCode(`// Scroll mouse wheel`);
|
||||
response.addCode(`await page.mouse.wheel(${params.deltaX}, ${params.deltaY});`);
|
||||
await tab.page.mouse.wheel(params.deltaX, params.deltaY);
|
||||
}
|
||||
});
|
||||
const mouseClick = (0, import_tool.defineTabTool)({
|
||||
capability: "vision",
|
||||
schema: {
|
||||
name: "browser_mouse_click_xy",
|
||||
title: "Click",
|
||||
description: "Click mouse button at a given position",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
x: import_zodBundle.z.number().describe("X coordinate"),
|
||||
y: import_zodBundle.z.number().describe("Y coordinate"),
|
||||
button: import_zodBundle.z.enum(["left", "right", "middle"]).optional().describe("Button to click, defaults to left"),
|
||||
clickCount: import_zodBundle.z.number().optional().describe("Number of clicks, defaults to 1"),
|
||||
delay: import_zodBundle.z.number().optional().describe("Time to wait between mouse down and mouse up in milliseconds, defaults to 0")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.setIncludeSnapshot();
|
||||
const options = {
|
||||
button: params.button,
|
||||
clickCount: params.clickCount,
|
||||
delay: params.delay
|
||||
};
|
||||
const formatted = (0, import_stringUtils.formatObjectOrVoid)(options);
|
||||
const optionsArg = formatted ? `, ${formatted}` : "";
|
||||
response.addCode(`// Click mouse at coordinates (${params.x}, ${params.y})`);
|
||||
response.addCode(`await page.mouse.click(${params.x}, ${params.y}${optionsArg});`);
|
||||
await tab.waitForCompletion(async () => {
|
||||
await tab.page.mouse.click(params.x, params.y, options);
|
||||
});
|
||||
}
|
||||
});
|
||||
const mouseDrag = (0, import_tool.defineTabTool)({
|
||||
capability: "vision",
|
||||
schema: {
|
||||
name: "browser_mouse_drag_xy",
|
||||
title: "Drag mouse",
|
||||
description: "Drag left mouse button to a given position",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
startX: import_zodBundle.z.number().describe("Start X coordinate"),
|
||||
startY: import_zodBundle.z.number().describe("Start Y coordinate"),
|
||||
endX: import_zodBundle.z.number().describe("End X coordinate"),
|
||||
endY: import_zodBundle.z.number().describe("End Y coordinate")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.setIncludeSnapshot();
|
||||
response.addCode(`// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`);
|
||||
response.addCode(`await page.mouse.move(${params.startX}, ${params.startY});`);
|
||||
response.addCode(`await page.mouse.down();`);
|
||||
response.addCode(`await page.mouse.move(${params.endX}, ${params.endY});`);
|
||||
response.addCode(`await page.mouse.up();`);
|
||||
await tab.waitForCompletion(async () => {
|
||||
await tab.page.mouse.move(params.startX, params.startY);
|
||||
await tab.page.mouse.down();
|
||||
await tab.page.mouse.move(params.endX, params.endY);
|
||||
await tab.page.mouse.up();
|
||||
});
|
||||
}
|
||||
});
|
||||
var mouse_default = [
|
||||
mouseMove,
|
||||
mouseClick,
|
||||
mouseDrag,
|
||||
mouseDown,
|
||||
mouseUp,
|
||||
mouseWheel
|
||||
];
|
||||
106
node_modules/playwright-core/lib/tools/backend/navigate.js
generated
vendored
Normal file
106
node_modules/playwright-core/lib/tools/backend/navigate.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var navigate_exports = {};
|
||||
__export(navigate_exports, {
|
||||
default: () => navigate_default
|
||||
});
|
||||
module.exports = __toCommonJS(navigate_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const navigate = (0, import_tool.defineTool)({
|
||||
capability: "core-navigation",
|
||||
schema: {
|
||||
name: "browser_navigate",
|
||||
title: "Navigate to a URL",
|
||||
description: "Navigate to a URL",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
url: import_zodBundle.z.string().describe("The URL to navigate to")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const tab = await context.ensureTab();
|
||||
let url = params.url;
|
||||
try {
|
||||
new URL(url);
|
||||
} catch (e) {
|
||||
if (url.startsWith("localhost"))
|
||||
url = "http://" + url;
|
||||
else
|
||||
url = "https://" + url;
|
||||
}
|
||||
context.checkUrlAllowed(url);
|
||||
await tab.navigate(url);
|
||||
response.setIncludeSnapshot();
|
||||
response.addCode(`await page.goto('${url}');`);
|
||||
}
|
||||
});
|
||||
const goBack = (0, import_tool.defineTabTool)({
|
||||
capability: "core-navigation",
|
||||
schema: {
|
||||
name: "browser_navigate_back",
|
||||
title: "Go back",
|
||||
description: "Go back to the previous page in the history",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.goBack(tab.navigationTimeoutOptions);
|
||||
response.setIncludeSnapshot();
|
||||
response.addCode(`await page.goBack();`);
|
||||
}
|
||||
});
|
||||
const goForward = (0, import_tool.defineTabTool)({
|
||||
capability: "core-navigation",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_navigate_forward",
|
||||
title: "Go forward",
|
||||
description: "Go forward to the next page in the history",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.goForward(tab.navigationTimeoutOptions);
|
||||
response.setIncludeSnapshot();
|
||||
response.addCode(`await page.goForward();`);
|
||||
}
|
||||
});
|
||||
const reload = (0, import_tool.defineTabTool)({
|
||||
capability: "core-navigation",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_reload",
|
||||
title: "Reload the page",
|
||||
description: "Reload the current page",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.reload(tab.navigationTimeoutOptions);
|
||||
response.setIncludeSnapshot();
|
||||
response.addCode(`await page.reload();`);
|
||||
}
|
||||
});
|
||||
var navigate_default = [
|
||||
navigate,
|
||||
goBack,
|
||||
goForward,
|
||||
reload
|
||||
];
|
||||
135
node_modules/playwright-core/lib/tools/backend/network.js
generated
vendored
Normal file
135
node_modules/playwright-core/lib/tools/backend/network.js
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var network_exports = {};
|
||||
__export(network_exports, {
|
||||
default: () => network_default,
|
||||
isFetch: () => isFetch,
|
||||
renderRequest: () => renderRequest
|
||||
});
|
||||
module.exports = __toCommonJS(network_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const requests = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_network_requests",
|
||||
title: "List network requests",
|
||||
description: "Returns all network requests since loading the page",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
static: import_zodBundle.z.boolean().default(false).describe("Whether to include successful static resources like images, fonts, scripts, etc. Defaults to false."),
|
||||
requestBody: import_zodBundle.z.boolean().default(false).describe("Whether to include request body. Defaults to false."),
|
||||
requestHeaders: import_zodBundle.z.boolean().default(false).describe("Whether to include request headers. Defaults to false."),
|
||||
filter: import_zodBundle.z.string().optional().describe('Only return requests whose URL matches this regexp (e.g. "/api/.*user").'),
|
||||
filename: import_zodBundle.z.string().optional().describe("Filename to save the network requests to. If not provided, requests are returned as text.")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const requests2 = await tab.requests();
|
||||
const filter = params.filter ? new RegExp(params.filter) : void 0;
|
||||
const text = [];
|
||||
for (const request of requests2) {
|
||||
if (!params.static && !isFetch(request) && isSuccessfulResponse(request))
|
||||
continue;
|
||||
if (filter) {
|
||||
filter.lastIndex = 0;
|
||||
if (!filter.test(request.url()))
|
||||
continue;
|
||||
}
|
||||
text.push(await renderRequest(request, params.requestBody, params.requestHeaders));
|
||||
}
|
||||
await response.addResult("Network", text.join("\n"), { prefix: "network", ext: "log", suggestedFilename: params.filename });
|
||||
}
|
||||
});
|
||||
const networkClear = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_network_clear",
|
||||
title: "Clear network requests",
|
||||
description: "Clear all network requests",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.clearRequests();
|
||||
}
|
||||
});
|
||||
function isSuccessfulResponse(request) {
|
||||
if (request.failure())
|
||||
return false;
|
||||
const response = request.existingResponse();
|
||||
return !!response && response.status() < 400;
|
||||
}
|
||||
function isFetch(request) {
|
||||
return ["fetch", "xhr"].includes(request.resourceType());
|
||||
}
|
||||
async function renderRequest(request, includeBody = false, includeHeaders = false) {
|
||||
const response = request.existingResponse();
|
||||
const result = [];
|
||||
result.push(`[${request.method().toUpperCase()}] ${request.url()}`);
|
||||
if (response)
|
||||
result.push(` => [${response.status()}] ${response.statusText()}`);
|
||||
else if (request.failure())
|
||||
result.push(` => [FAILED] ${request.failure()?.errorText ?? "Unknown error"}`);
|
||||
if (includeHeaders) {
|
||||
const headers = request.headers();
|
||||
const headerLines = Object.entries(headers).map(([k, v]) => ` ${k}: ${v}`).join("\n");
|
||||
if (headerLines)
|
||||
result.push(`
|
||||
Request headers:
|
||||
${headerLines}`);
|
||||
}
|
||||
if (includeBody) {
|
||||
const postData = request.postData();
|
||||
if (postData)
|
||||
result.push(`
|
||||
Request body: ${postData}`);
|
||||
}
|
||||
return result.join("");
|
||||
}
|
||||
const networkStateSet = (0, import_tool.defineTool)({
|
||||
capability: "network",
|
||||
schema: {
|
||||
name: "browser_network_state_set",
|
||||
title: "Set network state",
|
||||
description: "Sets the browser network state to online or offline. When offline, all network requests will fail.",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
state: import_zodBundle.z.enum(["online", "offline"]).describe('Set to "offline" to simulate offline mode, "online" to restore network connectivity')
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
const offline = params.state === "offline";
|
||||
await browserContext.setOffline(offline);
|
||||
response.addTextResult(`Network is now ${params.state}`);
|
||||
response.addCode(`await page.context().setOffline(${offline});`);
|
||||
}
|
||||
});
|
||||
var network_default = [
|
||||
requests,
|
||||
networkClear,
|
||||
networkStateSet
|
||||
];
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
isFetch,
|
||||
renderRequest
|
||||
});
|
||||
48
node_modules/playwright-core/lib/tools/backend/pdf.js
generated
vendored
Normal file
48
node_modules/playwright-core/lib/tools/backend/pdf.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var pdf_exports = {};
|
||||
__export(pdf_exports, {
|
||||
default: () => pdf_default
|
||||
});
|
||||
module.exports = __toCommonJS(pdf_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
||||
var import_tool = require("./tool");
|
||||
const pdfSchema = import_zodBundle.z.object({
|
||||
filename: import_zodBundle.z.string().optional().describe("File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified. Prefer relative file names to stay within the output directory.")
|
||||
});
|
||||
const pdf = (0, import_tool.defineTabTool)({
|
||||
capability: "pdf",
|
||||
schema: {
|
||||
name: "browser_pdf_save",
|
||||
title: "Save as PDF",
|
||||
description: "Save page as PDF",
|
||||
inputSchema: pdfSchema,
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const data = await tab.page.pdf();
|
||||
const result = await response.resolveClientFile({ prefix: "page", ext: "pdf", suggestedFilename: params.filename }, "Page as pdf");
|
||||
await response.addFileResult(result, data);
|
||||
response.addCode(`await page.pdf(${(0, import_stringUtils.formatObject)({ path: result.relativeName })});`);
|
||||
}
|
||||
});
|
||||
var pdf_default = [
|
||||
pdf
|
||||
];
|
||||
305
node_modules/playwright-core/lib/tools/backend/response.js
generated
vendored
Normal file
305
node_modules/playwright-core/lib/tools/backend/response.js
generated
vendored
Normal file
@@ -0,0 +1,305 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var response_exports = {};
|
||||
__export(response_exports, {
|
||||
Response: () => Response,
|
||||
parseResponse: () => parseResponse,
|
||||
renderTabMarkdown: () => renderTabMarkdown,
|
||||
renderTabsMarkdown: () => renderTabsMarkdown,
|
||||
requestDebug: () => requestDebug
|
||||
});
|
||||
module.exports = __toCommonJS(response_exports);
|
||||
var import_fs = __toESM(require("fs"));
|
||||
var import_path = __toESM(require("path"));
|
||||
var import_utilsBundle = require("../../utilsBundle");
|
||||
var import_tab = require("./tab");
|
||||
var import_screenshot = require("./screenshot");
|
||||
const requestDebug = (0, import_utilsBundle.debug)("pw:mcp:request");
|
||||
class Response {
|
||||
constructor(context, toolName, toolArgs, relativeTo) {
|
||||
this._results = [];
|
||||
this._errors = [];
|
||||
this._code = [];
|
||||
this._includeSnapshot = "none";
|
||||
this._isClose = false;
|
||||
this._imageResults = [];
|
||||
this._context = context;
|
||||
this.toolName = toolName;
|
||||
this.toolArgs = toolArgs;
|
||||
this._clientWorkspace = relativeTo ?? context.options.cwd;
|
||||
}
|
||||
_computRelativeTo(fileName) {
|
||||
return import_path.default.relative(this._clientWorkspace, fileName);
|
||||
}
|
||||
async resolveClientFile(template, title) {
|
||||
let fileName;
|
||||
if (template.suggestedFilename)
|
||||
fileName = await this.resolveClientFilename(template.suggestedFilename);
|
||||
else
|
||||
fileName = await this._context.outputFile(template, { origin: "llm" });
|
||||
const relativeName = this._computRelativeTo(fileName);
|
||||
const printableLink = `- [${title}](${relativeName})`;
|
||||
return { fileName, relativeName, printableLink };
|
||||
}
|
||||
async resolveClientFilename(filename) {
|
||||
return await this._context.workspaceFile(filename, this._clientWorkspace);
|
||||
}
|
||||
addTextResult(text) {
|
||||
this._results.push(text);
|
||||
}
|
||||
async addResult(title, data, file) {
|
||||
if (file.suggestedFilename || typeof data !== "string") {
|
||||
const resolvedFile = await this.resolveClientFile(file, title);
|
||||
await this.addFileResult(resolvedFile, data);
|
||||
} else {
|
||||
this.addTextResult(data);
|
||||
}
|
||||
}
|
||||
async _writeFile(resolvedFile, data) {
|
||||
if (typeof data === "string")
|
||||
await import_fs.default.promises.writeFile(resolvedFile.fileName, this._redactSecrets(data), "utf-8");
|
||||
else if (data)
|
||||
await import_fs.default.promises.writeFile(resolvedFile.fileName, data);
|
||||
}
|
||||
async addFileResult(resolvedFile, data) {
|
||||
await this._writeFile(resolvedFile, data);
|
||||
this.addTextResult(resolvedFile.printableLink);
|
||||
}
|
||||
addFileLink(title, fileName) {
|
||||
const relativeName = this._computRelativeTo(fileName);
|
||||
this.addTextResult(`- [${title}](${relativeName})`);
|
||||
}
|
||||
async registerImageResult(data, imageType) {
|
||||
this._imageResults.push({ data, imageType });
|
||||
}
|
||||
setClose() {
|
||||
this._isClose = true;
|
||||
}
|
||||
addError(error) {
|
||||
this._errors.push(error);
|
||||
}
|
||||
addCode(code) {
|
||||
this._code.push(code);
|
||||
}
|
||||
setIncludeSnapshot() {
|
||||
this._includeSnapshot = this._context.config.snapshot?.mode ?? "full";
|
||||
}
|
||||
setIncludeFullSnapshot(includeSnapshotFileName, selector, depth) {
|
||||
this._includeSnapshot = "explicit";
|
||||
this._includeSnapshotFileName = includeSnapshotFileName;
|
||||
this._includeSnapshotDepth = depth;
|
||||
this._includeSnapshotSelector = selector;
|
||||
}
|
||||
_redactSecrets(text) {
|
||||
for (const [secretName, secretValue] of Object.entries(this._context.config.secrets ?? {})) {
|
||||
if (!secretValue)
|
||||
continue;
|
||||
text = text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
async serialize() {
|
||||
const sections = await this._build();
|
||||
const text = [];
|
||||
for (const section of sections) {
|
||||
if (!section.content.length)
|
||||
continue;
|
||||
text.push(`### ${section.title}`);
|
||||
if (section.codeframe)
|
||||
text.push(`\`\`\`${section.codeframe}`);
|
||||
text.push(...section.content);
|
||||
if (section.codeframe)
|
||||
text.push("```");
|
||||
}
|
||||
const content = [
|
||||
{
|
||||
type: "text",
|
||||
text: sanitizeUnicode(this._redactSecrets(text.join("\n")))
|
||||
}
|
||||
];
|
||||
if (this._context.config.imageResponses !== "omit") {
|
||||
for (const imageResult of this._imageResults) {
|
||||
const scaledData = (0, import_screenshot.scaleImageToFitMessage)(imageResult.data, imageResult.imageType);
|
||||
content.push({ type: "image", data: scaledData.toString("base64"), mimeType: imageResult.imageType === "png" ? "image/png" : "image/jpeg" });
|
||||
}
|
||||
}
|
||||
return {
|
||||
content,
|
||||
...this._isClose ? { isClose: true } : {},
|
||||
...sections.some((section) => section.isError) ? { isError: true } : {}
|
||||
};
|
||||
}
|
||||
async _build() {
|
||||
const sections = [];
|
||||
const addSection = (title, content, codeframe) => {
|
||||
const section = { title, content, isError: title === "Error", codeframe };
|
||||
sections.push(section);
|
||||
return content;
|
||||
};
|
||||
if (this._errors.length)
|
||||
addSection("Error", this._errors);
|
||||
if (this._results.length)
|
||||
addSection("Result", this._results);
|
||||
if (this._context.config.codegen !== "none" && this._code.length)
|
||||
addSection("Ran Playwright code", this._code, "js");
|
||||
const tabSnapshot = this._context.currentTab() ? await this._context.currentTabOrDie().captureSnapshot(this._includeSnapshotSelector, this._includeSnapshotDepth, this._clientWorkspace) : void 0;
|
||||
const tabHeaders = await Promise.all(this._context.tabs().map((tab) => tab.headerSnapshot()));
|
||||
if (this._includeSnapshot !== "none" || tabHeaders.some((header) => header.changed)) {
|
||||
if (tabHeaders.length !== 1)
|
||||
addSection("Open tabs", renderTabsMarkdown(tabHeaders));
|
||||
addSection("Page", renderTabMarkdown(tabHeaders.find((h) => h.current) ?? tabHeaders[0]));
|
||||
}
|
||||
if (this._context.tabs().length === 0)
|
||||
this._isClose = true;
|
||||
if (tabSnapshot?.modalStates.length)
|
||||
addSection("Modal state", (0, import_tab.renderModalStates)(this._context.config, tabSnapshot.modalStates));
|
||||
if (tabSnapshot && this._includeSnapshot !== "none") {
|
||||
if (this._includeSnapshot !== "explicit" || this._includeSnapshotFileName) {
|
||||
const suggestedFilename = this._includeSnapshotFileName === "<auto>" ? void 0 : this._includeSnapshotFileName;
|
||||
const resolvedFile = await this.resolveClientFile({ prefix: "page", ext: "yml", suggestedFilename }, "Snapshot");
|
||||
await this._writeFile(resolvedFile, tabSnapshot.ariaSnapshot);
|
||||
addSection("Snapshot", [resolvedFile.printableLink]);
|
||||
} else {
|
||||
addSection("Snapshot", [tabSnapshot.ariaSnapshot], "yaml");
|
||||
}
|
||||
}
|
||||
const text = [];
|
||||
if (tabSnapshot?.consoleLink)
|
||||
text.push(`- New console entries: ${tabSnapshot.consoleLink}`);
|
||||
if (tabSnapshot?.events.filter((event) => event.type !== "request").length) {
|
||||
for (const event of tabSnapshot.events) {
|
||||
if (event.type === "download-start")
|
||||
text.push(`- Downloading file ${event.download.download.suggestedFilename()} ...`);
|
||||
else if (event.type === "download-finish")
|
||||
text.push(`- Downloaded file ${event.download.download.suggestedFilename()} to "${this._computRelativeTo(event.download.outputFile)}"`);
|
||||
}
|
||||
}
|
||||
if (text.length)
|
||||
addSection("Events", text);
|
||||
const pausedDetails = this._context.debugger().pausedDetails();
|
||||
if (pausedDetails) {
|
||||
addSection("Paused", [
|
||||
`- ${pausedDetails.title} at ${this._computRelativeTo(pausedDetails.location.file)}${pausedDetails.location.line ? ":" + pausedDetails.location.line : ""}`,
|
||||
"- Use any tools to explore and interact, resume by calling resume/step-over/pause-at"
|
||||
]);
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
}
|
||||
function renderTabMarkdown(tab) {
|
||||
const lines = [`- Page URL: ${tab.url}`];
|
||||
if (tab.title)
|
||||
lines.push(`- Page Title: ${tab.title}`);
|
||||
if (tab.console.errors || tab.console.warnings)
|
||||
lines.push(`- Console: ${tab.console.errors} errors, ${tab.console.warnings} warnings`);
|
||||
return lines;
|
||||
}
|
||||
function renderTabsMarkdown(tabs) {
|
||||
if (!tabs.length)
|
||||
return ["No open tabs. Navigate to a URL to create one."];
|
||||
const lines = [];
|
||||
for (let i = 0; i < tabs.length; i++) {
|
||||
const tab = tabs[i];
|
||||
const current = tab.current ? " (current)" : "";
|
||||
lines.push(`- ${i}:${current} [${tab.title}](${tab.url})`);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
function sanitizeUnicode(text) {
|
||||
return text.toWellFormed?.() ?? text;
|
||||
}
|
||||
function parseSections(text) {
|
||||
const sections = /* @__PURE__ */ new Map();
|
||||
const sectionHeaders = text.split(/^### /m).slice(1);
|
||||
for (const section of sectionHeaders) {
|
||||
const firstNewlineIndex = section.indexOf("\n");
|
||||
if (firstNewlineIndex === -1)
|
||||
continue;
|
||||
const sectionName = section.substring(0, firstNewlineIndex);
|
||||
const sectionContent = section.substring(firstNewlineIndex + 1).trim();
|
||||
sections.set(sectionName, sectionContent);
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
function parseResponse(response, cwd) {
|
||||
if (response.content?.[0].type !== "text")
|
||||
return void 0;
|
||||
const text = response.content[0].text;
|
||||
const sections = parseSections(text);
|
||||
const error = sections.get("Error");
|
||||
const result = sections.get("Result");
|
||||
const code = sections.get("Ran Playwright code");
|
||||
const tabs = sections.get("Open tabs");
|
||||
const page = sections.get("Page");
|
||||
const snapshotSection = sections.get("Snapshot");
|
||||
const events = sections.get("Events");
|
||||
const modalState = sections.get("Modal state");
|
||||
const paused = sections.get("Paused");
|
||||
const codeNoFrame = code?.replace(/^```js\n/, "").replace(/\n```$/, "");
|
||||
const isError = response.isError;
|
||||
const attachments = response.content.length > 1 ? response.content.slice(1) : void 0;
|
||||
let snapshot;
|
||||
let inlineSnapshot;
|
||||
if (snapshotSection) {
|
||||
const match = snapshotSection.match(/\[Snapshot\]\(([^)]+)\)/);
|
||||
if (match) {
|
||||
if (cwd) {
|
||||
try {
|
||||
snapshot = import_fs.default.readFileSync(import_path.default.resolve(cwd, match[1]), "utf-8");
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inlineSnapshot = snapshotSection.replace(/^```yaml\n?/, "").replace(/\n?```$/, "");
|
||||
}
|
||||
}
|
||||
return {
|
||||
result,
|
||||
error,
|
||||
code: codeNoFrame,
|
||||
tabs,
|
||||
page,
|
||||
snapshot,
|
||||
inlineSnapshot,
|
||||
events,
|
||||
modalState,
|
||||
paused,
|
||||
isError,
|
||||
attachments,
|
||||
text
|
||||
};
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
Response,
|
||||
parseResponse,
|
||||
renderTabMarkdown,
|
||||
renderTabsMarkdown,
|
||||
requestDebug
|
||||
});
|
||||
140
node_modules/playwright-core/lib/tools/backend/route.js
generated
vendored
Normal file
140
node_modules/playwright-core/lib/tools/backend/route.js
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var route_exports = {};
|
||||
__export(route_exports, {
|
||||
default: () => route_default
|
||||
});
|
||||
module.exports = __toCommonJS(route_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const route = (0, import_tool.defineTool)({
|
||||
capability: "network",
|
||||
schema: {
|
||||
name: "browser_route",
|
||||
title: "Mock network requests",
|
||||
description: "Set up a route to mock network requests matching a URL pattern",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
pattern: import_zodBundle.z.string().describe('URL pattern to match (e.g., "**/api/users", "**/*.{png,jpg}")'),
|
||||
status: import_zodBundle.z.number().optional().describe("HTTP status code to return (default: 200)"),
|
||||
body: import_zodBundle.z.string().optional().describe("Response body (text or JSON string)"),
|
||||
contentType: import_zodBundle.z.string().optional().describe('Content-Type header (e.g., "application/json", "text/html")'),
|
||||
headers: import_zodBundle.z.array(import_zodBundle.z.string()).optional().describe('Headers to add in "Name: Value" format'),
|
||||
removeHeaders: import_zodBundle.z.string().optional().describe("Comma-separated list of header names to remove from request")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const addHeaders = params.headers ? Object.fromEntries(params.headers.map((h) => {
|
||||
const colonIndex = h.indexOf(":");
|
||||
return [h.substring(0, colonIndex).trim(), h.substring(colonIndex + 1).trim()];
|
||||
})) : void 0;
|
||||
const removeHeaders = params.removeHeaders ? params.removeHeaders.split(",").map((h) => h.trim()) : void 0;
|
||||
const handler = async (route2) => {
|
||||
if (params.body !== void 0 || params.status !== void 0) {
|
||||
await route2.fulfill({
|
||||
status: params.status ?? 200,
|
||||
contentType: params.contentType,
|
||||
body: params.body
|
||||
});
|
||||
return;
|
||||
}
|
||||
const headers = { ...route2.request().headers() };
|
||||
if (addHeaders) {
|
||||
for (const [key, value] of Object.entries(addHeaders))
|
||||
headers[key] = value;
|
||||
}
|
||||
if (removeHeaders) {
|
||||
for (const header of removeHeaders)
|
||||
delete headers[header.toLowerCase()];
|
||||
}
|
||||
await route2.continue({ headers });
|
||||
};
|
||||
const entry = {
|
||||
pattern: params.pattern,
|
||||
status: params.status,
|
||||
body: params.body,
|
||||
contentType: params.contentType,
|
||||
addHeaders,
|
||||
removeHeaders,
|
||||
handler
|
||||
};
|
||||
await context.addRoute(entry);
|
||||
response.addTextResult(`Route added for pattern: ${params.pattern}`);
|
||||
response.addCode(`await page.context().route('${params.pattern}', async route => { /* route handler */ });`);
|
||||
}
|
||||
});
|
||||
const routeList = (0, import_tool.defineTool)({
|
||||
capability: "network",
|
||||
schema: {
|
||||
name: "browser_route_list",
|
||||
title: "List network routes",
|
||||
description: "List all active network routes",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const routes = context.routes();
|
||||
if (routes.length === 0) {
|
||||
response.addTextResult("No active routes");
|
||||
return;
|
||||
}
|
||||
const lines = [];
|
||||
for (let i = 0; i < routes.length; i++) {
|
||||
const route2 = routes[i];
|
||||
const details = [];
|
||||
if (route2.status !== void 0)
|
||||
details.push(`status=${route2.status}`);
|
||||
if (route2.body !== void 0)
|
||||
details.push(`body=${route2.body.length > 50 ? route2.body.substring(0, 50) + "..." : route2.body}`);
|
||||
if (route2.contentType)
|
||||
details.push(`contentType=${route2.contentType}`);
|
||||
if (route2.addHeaders)
|
||||
details.push(`addHeaders=${JSON.stringify(route2.addHeaders)}`);
|
||||
if (route2.removeHeaders)
|
||||
details.push(`removeHeaders=${route2.removeHeaders.join(",")}`);
|
||||
const detailsStr = details.length ? ` (${details.join(", ")})` : "";
|
||||
lines.push(`${i + 1}. ${route2.pattern}${detailsStr}`);
|
||||
}
|
||||
response.addTextResult(lines.join("\n"));
|
||||
}
|
||||
});
|
||||
const unroute = (0, import_tool.defineTool)({
|
||||
capability: "network",
|
||||
schema: {
|
||||
name: "browser_unroute",
|
||||
title: "Remove network routes",
|
||||
description: "Remove network routes matching a pattern (or all routes if no pattern specified)",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
pattern: import_zodBundle.z.string().optional().describe("URL pattern to unroute (omit to remove all routes)")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const removed = await context.removeRoute(params.pattern);
|
||||
if (params.pattern)
|
||||
response.addTextResult(`Removed ${removed} route(s) for pattern: ${params.pattern}`);
|
||||
else
|
||||
response.addTextResult(`Removed all ${removed} route(s)`);
|
||||
}
|
||||
});
|
||||
var route_default = [
|
||||
route,
|
||||
routeList,
|
||||
unroute
|
||||
];
|
||||
77
node_modules/playwright-core/lib/tools/backend/runCode.js
generated
vendored
Normal file
77
node_modules/playwright-core/lib/tools/backend/runCode.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var runCode_exports = {};
|
||||
__export(runCode_exports, {
|
||||
default: () => runCode_default
|
||||
});
|
||||
module.exports = __toCommonJS(runCode_exports);
|
||||
var import_fs = __toESM(require("fs"));
|
||||
var import_vm = __toESM(require("vm"));
|
||||
var import_manualPromise = require("../../utils/isomorphic/manualPromise");
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const codeSchema = import_zodBundle.z.object({
|
||||
code: import_zodBundle.z.string().optional().describe(`A JavaScript function containing Playwright code to execute. It will be invoked with a single argument, page, which you can use for any page interaction. For example: \`async (page) => { await page.getByRole('button', { name: 'Submit' }).click(); return await page.title(); }\``),
|
||||
filename: import_zodBundle.z.string().optional().describe("Load code from the specified file. If both code and filename are provided, code will be ignored.")
|
||||
});
|
||||
const runCode = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_run_code",
|
||||
title: "Run Playwright code",
|
||||
description: "Run Playwright code snippet",
|
||||
inputSchema: codeSchema,
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
let code = params.code;
|
||||
if (params.filename) {
|
||||
const resolvedPath = await response.resolveClientFilename(params.filename);
|
||||
code = await import_fs.default.promises.readFile(resolvedPath, "utf-8");
|
||||
}
|
||||
response.addCode(`await (${code})(page);`);
|
||||
const __end__ = new import_manualPromise.ManualPromise();
|
||||
const context = {
|
||||
page: tab.page,
|
||||
__end__
|
||||
};
|
||||
import_vm.default.createContext(context);
|
||||
await tab.waitForCompletion(async () => {
|
||||
context.__fn__ = import_vm.default.runInContext("(" + code + ")", context);
|
||||
const snippet = "(async () => {\n try {\n const result = await __fn__(page);\n __end__.resolve(JSON.stringify(result));\n } catch (e) {\n __end__.reject(e);\n }\n})()";
|
||||
await import_vm.default.runInContext(snippet, context);
|
||||
const result = await __end__;
|
||||
if (typeof result === "string")
|
||||
response.addTextResult(result);
|
||||
});
|
||||
}
|
||||
});
|
||||
var runCode_default = [
|
||||
runCode
|
||||
];
|
||||
88
node_modules/playwright-core/lib/tools/backend/screenshot.js
generated
vendored
Normal file
88
node_modules/playwright-core/lib/tools/backend/screenshot.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var screenshot_exports = {};
|
||||
__export(screenshot_exports, {
|
||||
default: () => screenshot_default,
|
||||
scaleImageToFitMessage: () => scaleImageToFitMessage
|
||||
});
|
||||
module.exports = __toCommonJS(screenshot_exports);
|
||||
var import_imageUtils = require("../../utils/isomorphic/imageUtils");
|
||||
var import_utilsBundle = require("../../utilsBundle");
|
||||
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const screenshotSchema = import_zodBundle.z.object({
|
||||
type: import_zodBundle.z.enum(["png", "jpeg"]).default("png").describe("Image format for the screenshot. Default is png."),
|
||||
filename: import_zodBundle.z.string().optional().describe("File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified. Prefer relative file names to stay within the output directory."),
|
||||
element: import_zodBundle.z.string().optional().describe("Human-readable element description used to obtain permission to screenshot the element. If not provided, the screenshot will be taken of viewport. If element is provided, ref must be provided too."),
|
||||
ref: import_zodBundle.z.string().optional().describe("Exact target element reference from the page snapshot. If not provided, the screenshot will be taken of viewport. If ref is provided, element must be provided too."),
|
||||
selector: import_zodBundle.z.string().optional().describe('CSS or role selector for the target element, when "ref" is not available.'),
|
||||
fullPage: import_zodBundle.z.boolean().optional().describe("When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Cannot be used with element screenshots.")
|
||||
});
|
||||
const screenshot = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_take_screenshot",
|
||||
title: "Take a screenshot",
|
||||
description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
|
||||
inputSchema: screenshotSchema,
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
if (params.fullPage && params.ref)
|
||||
throw new Error("fullPage cannot be used with element screenshots.");
|
||||
const fileType = params.type || "png";
|
||||
const options = {
|
||||
type: fileType,
|
||||
quality: fileType === "png" ? void 0 : 90,
|
||||
scale: "css",
|
||||
...tab.actionTimeoutOptions,
|
||||
...params.fullPage !== void 0 && { fullPage: params.fullPage }
|
||||
};
|
||||
const screenshotTarget = params.ref ? params.element || "element" : params.fullPage ? "full page" : "viewport";
|
||||
const ref = params.ref || params.selector ? await tab.refLocator({ element: params.element || "", ref: params.ref || "", selector: params.selector }) : null;
|
||||
const data = ref ? await ref.locator.screenshot(options) : await tab.page.screenshot(options);
|
||||
const resolvedFile = await response.resolveClientFile({ prefix: ref ? "element" : "page", ext: fileType, suggestedFilename: params.filename }, `Screenshot of ${screenshotTarget}`);
|
||||
response.addCode(`// Screenshot ${screenshotTarget} and save it as ${resolvedFile.relativeName}`);
|
||||
if (ref)
|
||||
response.addCode(`await page.${ref.resolved}.screenshot(${(0, import_stringUtils.formatObject)({ ...options, path: resolvedFile.relativeName })});`);
|
||||
else
|
||||
response.addCode(`await page.screenshot(${(0, import_stringUtils.formatObject)({ ...options, path: resolvedFile.relativeName })});`);
|
||||
await response.addFileResult(resolvedFile, data);
|
||||
await response.registerImageResult(data, fileType);
|
||||
}
|
||||
});
|
||||
function scaleImageToFitMessage(buffer, imageType) {
|
||||
const image = imageType === "png" ? import_utilsBundle.PNG.sync.read(buffer) : import_utilsBundle.jpegjs.decode(buffer, { maxMemoryUsageInMB: 512 });
|
||||
const pixels = image.width * image.height;
|
||||
const shrink = Math.min(1568 / image.width, 1568 / image.height, Math.sqrt(1.15 * 1024 * 1024 / pixels));
|
||||
if (shrink > 1)
|
||||
return buffer;
|
||||
const width = image.width * shrink | 0;
|
||||
const height = image.height * shrink | 0;
|
||||
const scaledImage = (0, import_imageUtils.scaleImageToSize)(image, { width, height });
|
||||
return imageType === "png" ? import_utilsBundle.PNG.sync.write(scaledImage) : import_utilsBundle.jpegjs.encode(scaledImage, 80).data;
|
||||
}
|
||||
var screenshot_default = [
|
||||
screenshot
|
||||
];
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
scaleImageToFitMessage
|
||||
});
|
||||
74
node_modules/playwright-core/lib/tools/backend/sessionLog.js
generated
vendored
Normal file
74
node_modules/playwright-core/lib/tools/backend/sessionLog.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var sessionLog_exports = {};
|
||||
__export(sessionLog_exports, {
|
||||
SessionLog: () => SessionLog
|
||||
});
|
||||
module.exports = __toCommonJS(sessionLog_exports);
|
||||
var import_fs = __toESM(require("fs"));
|
||||
var import_path = __toESM(require("path"));
|
||||
var import_context = require("./context");
|
||||
var import_response = require("./response");
|
||||
class SessionLog {
|
||||
constructor(sessionFolder, cwd) {
|
||||
this._sessionFileQueue = Promise.resolve();
|
||||
this._folder = sessionFolder;
|
||||
this._file = import_path.default.join(this._folder, "session.md");
|
||||
this._cwd = cwd;
|
||||
}
|
||||
static async create(config, cwd) {
|
||||
const sessionFolder = await (0, import_context.outputFile)({ config, cwd }, `session-${Date.now()}`, { origin: "code" });
|
||||
await import_fs.default.promises.mkdir(sessionFolder, { recursive: true });
|
||||
console.error(`Session: ${sessionFolder}`);
|
||||
return new SessionLog(sessionFolder, cwd);
|
||||
}
|
||||
logResponse(toolName, toolArgs, responseObject) {
|
||||
const parsed = { ...(0, import_response.parseResponse)(responseObject, this._cwd), text: void 0 };
|
||||
const lines = [""];
|
||||
lines.push(
|
||||
`### Tool call: ${toolName}`,
|
||||
`- Args`,
|
||||
"```json",
|
||||
JSON.stringify(toolArgs, null, 2),
|
||||
"```"
|
||||
);
|
||||
if (parsed) {
|
||||
lines.push(`- Result`);
|
||||
lines.push("```json");
|
||||
lines.push(JSON.stringify(parsed, null, 2));
|
||||
lines.push("```");
|
||||
}
|
||||
lines.push("");
|
||||
this._sessionFileQueue = this._sessionFileQueue.then(() => import_fs.default.promises.appendFile(this._file, lines.join("\n")));
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
SessionLog
|
||||
});
|
||||
208
node_modules/playwright-core/lib/tools/backend/snapshot.js
generated
vendored
Normal file
208
node_modules/playwright-core/lib/tools/backend/snapshot.js
generated
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var snapshot_exports = {};
|
||||
__export(snapshot_exports, {
|
||||
default: () => snapshot_default,
|
||||
elementSchema: () => elementSchema
|
||||
});
|
||||
module.exports = __toCommonJS(snapshot_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
||||
var import_tool = require("./tool");
|
||||
const snapshot = (0, import_tool.defineTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_snapshot",
|
||||
title: "Page snapshot",
|
||||
description: "Capture accessibility snapshot of the current page, this is better than screenshot",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
filename: import_zodBundle.z.string().optional().describe("Save snapshot to markdown file instead of returning it in the response."),
|
||||
selector: import_zodBundle.z.string().optional().describe("Element selector of the root element to capture a partial snapshot instead of the whole page"),
|
||||
depth: import_zodBundle.z.number().optional().describe("Limit the depth of the snapshot tree")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
await context.ensureTab();
|
||||
response.setIncludeFullSnapshot(params.filename, params.selector, params.depth);
|
||||
}
|
||||
});
|
||||
const elementSchema = import_zodBundle.z.object({
|
||||
element: import_zodBundle.z.string().optional().describe("Human-readable element description used to obtain permission to interact with the element"),
|
||||
ref: import_zodBundle.z.string().describe("Exact target element reference from the page snapshot"),
|
||||
selector: import_zodBundle.z.string().optional().describe('CSS or role selector for the target element, when "ref" is not available')
|
||||
});
|
||||
const clickSchema = elementSchema.extend({
|
||||
doubleClick: import_zodBundle.z.boolean().optional().describe("Whether to perform a double click instead of a single click"),
|
||||
button: import_zodBundle.z.enum(["left", "right", "middle"]).optional().describe("Button to click, defaults to left"),
|
||||
modifiers: import_zodBundle.z.array(import_zodBundle.z.enum(["Alt", "Control", "ControlOrMeta", "Meta", "Shift"])).optional().describe("Modifier keys to press")
|
||||
});
|
||||
const click = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_click",
|
||||
title: "Click",
|
||||
description: "Perform click on a web page",
|
||||
inputSchema: clickSchema,
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.setIncludeSnapshot();
|
||||
const { locator, resolved } = await tab.refLocator(params);
|
||||
const options = {
|
||||
button: params.button,
|
||||
modifiers: params.modifiers,
|
||||
...tab.actionTimeoutOptions
|
||||
};
|
||||
const optionsArg = (0, import_stringUtils.formatObjectOrVoid)(options);
|
||||
if (params.doubleClick)
|
||||
response.addCode(`await page.${resolved}.dblclick(${optionsArg});`);
|
||||
else
|
||||
response.addCode(`await page.${resolved}.click(${optionsArg});`);
|
||||
await tab.waitForCompletion(async () => {
|
||||
if (params.doubleClick)
|
||||
await locator.dblclick(options);
|
||||
else
|
||||
await locator.click(options);
|
||||
});
|
||||
}
|
||||
});
|
||||
const drag = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_drag",
|
||||
title: "Drag mouse",
|
||||
description: "Perform drag and drop between two elements",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
startElement: import_zodBundle.z.string().describe("Human-readable source element description used to obtain the permission to interact with the element"),
|
||||
startRef: import_zodBundle.z.string().describe("Exact source element reference from the page snapshot"),
|
||||
startSelector: import_zodBundle.z.string().optional().describe("CSS or role selector for the source element, when ref is not available"),
|
||||
endElement: import_zodBundle.z.string().describe("Human-readable target element description used to obtain the permission to interact with the element"),
|
||||
endRef: import_zodBundle.z.string().describe("Exact target element reference from the page snapshot"),
|
||||
endSelector: import_zodBundle.z.string().optional().describe("CSS or role selector for the target element, when ref is not available")
|
||||
}),
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.setIncludeSnapshot();
|
||||
const [start, end] = await tab.refLocators([
|
||||
{ ref: params.startRef, selector: params.startSelector, element: params.startElement },
|
||||
{ ref: params.endRef, selector: params.endSelector, element: params.endElement }
|
||||
]);
|
||||
await tab.waitForCompletion(async () => {
|
||||
await start.locator.dragTo(end.locator, tab.actionTimeoutOptions);
|
||||
});
|
||||
response.addCode(`await page.${start.resolved}.dragTo(page.${end.resolved});`);
|
||||
}
|
||||
});
|
||||
const hover = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_hover",
|
||||
title: "Hover mouse",
|
||||
description: "Hover over element on page",
|
||||
inputSchema: elementSchema,
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.setIncludeSnapshot();
|
||||
const { locator, resolved } = await tab.refLocator(params);
|
||||
response.addCode(`await page.${resolved}.hover();`);
|
||||
await locator.hover(tab.actionTimeoutOptions);
|
||||
}
|
||||
});
|
||||
const selectOptionSchema = elementSchema.extend({
|
||||
values: import_zodBundle.z.array(import_zodBundle.z.string()).describe("Array of values to select in the dropdown. This can be a single value or multiple values.")
|
||||
});
|
||||
const selectOption = (0, import_tool.defineTabTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_select_option",
|
||||
title: "Select option",
|
||||
description: "Select an option in a dropdown",
|
||||
inputSchema: selectOptionSchema,
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
response.setIncludeSnapshot();
|
||||
const { locator, resolved } = await tab.refLocator(params);
|
||||
response.addCode(`await page.${resolved}.selectOption(${(0, import_stringUtils.formatObject)(params.values)});`);
|
||||
await locator.selectOption(params.values, tab.actionTimeoutOptions);
|
||||
}
|
||||
});
|
||||
const pickLocator = (0, import_tool.defineTabTool)({
|
||||
capability: "testing",
|
||||
schema: {
|
||||
name: "browser_generate_locator",
|
||||
title: "Create locator for element",
|
||||
description: "Generate locator for the given element to use in tests",
|
||||
inputSchema: elementSchema,
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const { resolved } = await tab.refLocator(params);
|
||||
response.addTextResult(resolved);
|
||||
}
|
||||
});
|
||||
const check = (0, import_tool.defineTabTool)({
|
||||
capability: "core-input",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_check",
|
||||
title: "Check",
|
||||
description: "Check a checkbox or radio button",
|
||||
inputSchema: elementSchema,
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const { locator, resolved } = await tab.refLocator(params);
|
||||
response.addCode(`await page.${resolved}.check();`);
|
||||
await locator.check(tab.actionTimeoutOptions);
|
||||
}
|
||||
});
|
||||
const uncheck = (0, import_tool.defineTabTool)({
|
||||
capability: "core-input",
|
||||
skillOnly: true,
|
||||
schema: {
|
||||
name: "browser_uncheck",
|
||||
title: "Uncheck",
|
||||
description: "Uncheck a checkbox or radio button",
|
||||
inputSchema: elementSchema,
|
||||
type: "input"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const { locator, resolved } = await tab.refLocator(params);
|
||||
response.addCode(`await page.${resolved}.uncheck();`);
|
||||
await locator.uncheck(tab.actionTimeoutOptions);
|
||||
}
|
||||
});
|
||||
var snapshot_default = [
|
||||
snapshot,
|
||||
click,
|
||||
drag,
|
||||
hover,
|
||||
selectOption,
|
||||
pickLocator,
|
||||
check,
|
||||
uncheck
|
||||
];
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
elementSchema
|
||||
});
|
||||
68
node_modules/playwright-core/lib/tools/backend/storage.js
generated
vendored
Normal file
68
node_modules/playwright-core/lib/tools/backend/storage.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var storage_exports = {};
|
||||
__export(storage_exports, {
|
||||
default: () => storage_default
|
||||
});
|
||||
module.exports = __toCommonJS(storage_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const storageState = (0, import_tool.defineTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_storage_state",
|
||||
title: "Save storage state",
|
||||
description: "Save storage state (cookies, local storage) to a file for later reuse",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
filename: import_zodBundle.z.string().optional().describe("File name to save the storage state to. Defaults to `storage-state-{timestamp}.json` if not specified.")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
const state = await browserContext.storageState();
|
||||
const serializedState = JSON.stringify(state, null, 2);
|
||||
const resolvedFile = await response.resolveClientFile({ prefix: "storage-state", ext: "json", suggestedFilename: params.filename }, "Storage state");
|
||||
response.addCode(`await page.context().storageState({ path: '${resolvedFile.relativeName}' });`);
|
||||
await response.addFileResult(resolvedFile, serializedState);
|
||||
}
|
||||
});
|
||||
const setStorageState = (0, import_tool.defineTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_set_storage_state",
|
||||
title: "Restore storage state",
|
||||
description: "Restore storage state (cookies, local storage) from a file. This clears existing cookies and local storage before restoring.",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
filename: import_zodBundle.z.string().describe("Path to the storage state file to restore from")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
const resolvedFilename = await response.resolveClientFilename(params.filename);
|
||||
await browserContext.setStorageState(resolvedFilename);
|
||||
response.addTextResult(`Storage state restored from ${params.filename}`);
|
||||
response.addCode(`await page.context().setStorageState('${params.filename}');`);
|
||||
}
|
||||
});
|
||||
var storage_default = [
|
||||
storageState,
|
||||
setStorageState
|
||||
];
|
||||
445
node_modules/playwright-core/lib/tools/backend/tab.js
generated
vendored
Normal file
445
node_modules/playwright-core/lib/tools/backend/tab.js
generated
vendored
Normal file
@@ -0,0 +1,445 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var tab_exports = {};
|
||||
__export(tab_exports, {
|
||||
Tab: () => Tab,
|
||||
renderModalStates: () => renderModalStates,
|
||||
shouldIncludeMessage: () => shouldIncludeMessage
|
||||
});
|
||||
module.exports = __toCommonJS(tab_exports);
|
||||
var import_url = __toESM(require("url"));
|
||||
var import_events = require("events");
|
||||
var import_locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
|
||||
var import_locatorParser = require("../../utils/isomorphic/locatorParser");
|
||||
var import_manualPromise = require("../../utils/isomorphic/manualPromise");
|
||||
var import_utilsBundle = require("../../utilsBundle");
|
||||
var import_eventsHelper = require("../../server/utils/eventsHelper");
|
||||
var import_disposable = require("../../server/utils/disposable");
|
||||
var import_utils = require("./utils");
|
||||
var import_logFile = require("./logFile");
|
||||
var import_dialogs = require("./dialogs");
|
||||
var import_files = require("./files");
|
||||
const TabEvents = {
|
||||
modalState: "modalState"
|
||||
};
|
||||
class Tab extends import_events.EventEmitter {
|
||||
constructor(context, page, onPageClose) {
|
||||
super();
|
||||
this._lastHeader = { title: "about:blank", url: "about:blank", current: false, console: { total: 0, warnings: 0, errors: 0 } };
|
||||
this._downloads = [];
|
||||
this._requests = [];
|
||||
this._modalStates = [];
|
||||
this._recentEventEntries = [];
|
||||
this.context = context;
|
||||
this.page = page;
|
||||
this._onPageClose = onPageClose;
|
||||
const p = page;
|
||||
this._disposables = [
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "console", (event) => this._handleConsoleMessage(messageToConsoleMessage(event))),
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "pageerror", (error) => this._handleConsoleMessage(pageErrorToConsoleMessage(error))),
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "request", (request) => this._handleRequest(request)),
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "response", (response) => this._handleResponse(response)),
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "requestfailed", (request) => this._handleRequestFailed(request)),
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "close", () => this._onClose()),
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "filechooser", (chooser) => {
|
||||
this.setModalState({
|
||||
type: "fileChooser",
|
||||
description: "File chooser",
|
||||
fileChooser: chooser,
|
||||
clearedBy: { tool: import_files.uploadFile.schema.name, skill: "upload" }
|
||||
});
|
||||
}),
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "dialog", (dialog) => this._dialogShown(dialog)),
|
||||
import_eventsHelper.eventsHelper.addEventListener(p, "download", (download) => {
|
||||
void this._downloadStarted(download);
|
||||
})
|
||||
];
|
||||
page[tabSymbol] = this;
|
||||
const wallTime = Date.now();
|
||||
this._consoleLog = new import_logFile.LogFile(this.context, wallTime, "console", "Console");
|
||||
this._initializedPromise = this._initialize();
|
||||
this.actionTimeoutOptions = { timeout: context.config.timeouts?.action };
|
||||
this.navigationTimeoutOptions = { timeout: context.config.timeouts?.navigation };
|
||||
this.expectTimeoutOptions = { timeout: context.config.timeouts?.expect };
|
||||
}
|
||||
async dispose() {
|
||||
await (0, import_disposable.disposeAll)(this._disposables);
|
||||
this._consoleLog.stop();
|
||||
}
|
||||
static forPage(page) {
|
||||
return page[tabSymbol];
|
||||
}
|
||||
static async collectConsoleMessages(page) {
|
||||
const result = [];
|
||||
const messages = await page.consoleMessages().catch(() => []);
|
||||
for (const message of messages)
|
||||
result.push(messageToConsoleMessage(message));
|
||||
const errors = await page.pageErrors().catch(() => []);
|
||||
for (const error of errors)
|
||||
result.push(pageErrorToConsoleMessage(error));
|
||||
return result;
|
||||
}
|
||||
async _initialize() {
|
||||
for (const message of await Tab.collectConsoleMessages(this.page))
|
||||
this._handleConsoleMessage(message);
|
||||
const requests = await this.page.requests().catch(() => []);
|
||||
for (const request of requests.filter((r) => r.existingResponse() || r.failure()))
|
||||
this._requests.push(request);
|
||||
for (const initPage of this.context.config.browser?.initPage || []) {
|
||||
try {
|
||||
const { default: func } = await import(import_url.default.pathToFileURL(initPage).href);
|
||||
await func({ page: this.page });
|
||||
} catch (e) {
|
||||
(0, import_utilsBundle.debug)("pw:tools:error")(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
modalStates() {
|
||||
return this._modalStates;
|
||||
}
|
||||
setModalState(modalState) {
|
||||
this._modalStates.push(modalState);
|
||||
this.emit(TabEvents.modalState, modalState);
|
||||
}
|
||||
clearModalState(modalState) {
|
||||
this._modalStates = this._modalStates.filter((state) => state !== modalState);
|
||||
}
|
||||
_dialogShown(dialog) {
|
||||
this.setModalState({
|
||||
type: "dialog",
|
||||
description: `"${dialog.type()}" dialog with message "${dialog.message()}"`,
|
||||
dialog,
|
||||
clearedBy: { tool: import_dialogs.handleDialog.schema.name, skill: "dialog-accept or dialog-dismiss" }
|
||||
});
|
||||
}
|
||||
async _downloadStarted(download) {
|
||||
const outputFile = await this.context.outputFile({ suggestedFilename: sanitizeForFilePath(download.suggestedFilename()), prefix: "download", ext: "bin" }, { origin: "code" });
|
||||
const entry = {
|
||||
download,
|
||||
finished: false,
|
||||
outputFile
|
||||
};
|
||||
this._downloads.push(entry);
|
||||
this._addLogEntry({ type: "download-start", wallTime: Date.now(), download: entry });
|
||||
await download.saveAs(entry.outputFile);
|
||||
entry.finished = true;
|
||||
this._addLogEntry({ type: "download-finish", wallTime: Date.now(), download: entry });
|
||||
}
|
||||
_clearCollectedArtifacts() {
|
||||
this._downloads.length = 0;
|
||||
this._requests.length = 0;
|
||||
this._recentEventEntries.length = 0;
|
||||
this._resetLogs();
|
||||
}
|
||||
_resetLogs() {
|
||||
const wallTime = Date.now();
|
||||
this._consoleLog.stop();
|
||||
this._consoleLog = new import_logFile.LogFile(this.context, wallTime, "console", "Console");
|
||||
}
|
||||
_handleRequest(request) {
|
||||
this._requests.push(request);
|
||||
const wallTime = request.timing().startTime || Date.now();
|
||||
this._addLogEntry({ type: "request", wallTime, request });
|
||||
}
|
||||
_handleResponse(response) {
|
||||
const timing = response.request().timing();
|
||||
const wallTime = timing.responseStart + timing.startTime;
|
||||
this._addLogEntry({ type: "request", wallTime, request: response.request() });
|
||||
}
|
||||
_handleRequestFailed(request) {
|
||||
this._requests.push(request);
|
||||
const timing = request.timing();
|
||||
const wallTime = timing.responseEnd + timing.startTime;
|
||||
this._addLogEntry({ type: "request", wallTime, request });
|
||||
}
|
||||
_handleConsoleMessage(message) {
|
||||
const wallTime = message.timestamp;
|
||||
this._addLogEntry({ type: "console", wallTime, message });
|
||||
if (shouldIncludeMessage(this.context.config.console?.level, message.type))
|
||||
this._consoleLog.appendLine(wallTime, message.toString());
|
||||
}
|
||||
_addLogEntry(entry) {
|
||||
this._recentEventEntries.push(entry);
|
||||
}
|
||||
_onClose() {
|
||||
this._clearCollectedArtifacts();
|
||||
this._onPageClose(this);
|
||||
}
|
||||
async headerSnapshot() {
|
||||
let title;
|
||||
await this._raceAgainstModalStates(async () => {
|
||||
title = await this.page.title();
|
||||
});
|
||||
const newHeader = {
|
||||
title: title ?? "",
|
||||
url: this.page.url(),
|
||||
current: this.isCurrentTab(),
|
||||
console: await this.consoleMessageCount()
|
||||
};
|
||||
if (!tabHeaderEquals(this._lastHeader, newHeader)) {
|
||||
this._lastHeader = newHeader;
|
||||
return { ...this._lastHeader, changed: true };
|
||||
}
|
||||
return { ...this._lastHeader, changed: false };
|
||||
}
|
||||
isCurrentTab() {
|
||||
return this === this.context.currentTab();
|
||||
}
|
||||
async waitForLoadState(state, options) {
|
||||
await this._initializedPromise;
|
||||
await this.page.waitForLoadState(state, options).catch((e) => (0, import_utilsBundle.debug)("pw:tools:error")(e));
|
||||
}
|
||||
async navigate(url2) {
|
||||
await this._initializedPromise;
|
||||
this._clearCollectedArtifacts();
|
||||
const { promise: downloadEvent, abort: abortDownloadEvent } = (0, import_utils.eventWaiter)(this.page, "download", 3e3);
|
||||
try {
|
||||
await this.page.goto(url2, { waitUntil: "domcontentloaded", ...this.navigationTimeoutOptions });
|
||||
abortDownloadEvent();
|
||||
} catch (_e) {
|
||||
const e = _e;
|
||||
const mightBeDownload = e.message.includes("net::ERR_ABORTED") || e.message.includes("Download is starting");
|
||||
if (!mightBeDownload)
|
||||
throw e;
|
||||
const download = await downloadEvent;
|
||||
if (!download)
|
||||
throw e;
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
return;
|
||||
}
|
||||
await this.waitForLoadState("load", { timeout: 5e3 });
|
||||
}
|
||||
async consoleMessageCount() {
|
||||
await this._initializedPromise;
|
||||
const messages = await this.page.consoleMessages({ filter: "since-navigation" });
|
||||
const pageErrors = await this.page.pageErrors({ filter: "since-navigation" });
|
||||
let errors = pageErrors.length;
|
||||
let warnings = 0;
|
||||
for (const message of messages) {
|
||||
if (message.type() === "error")
|
||||
errors++;
|
||||
else if (message.type() === "warning")
|
||||
warnings++;
|
||||
}
|
||||
return { total: messages.length + pageErrors.length, errors, warnings };
|
||||
}
|
||||
async consoleMessages(level, all) {
|
||||
await this._initializedPromise;
|
||||
const result = [];
|
||||
const messages = await this.page.consoleMessages({ filter: all ? "all" : "since-navigation" });
|
||||
for (const message of messages) {
|
||||
const cm = messageToConsoleMessage(message);
|
||||
if (shouldIncludeMessage(level, cm.type))
|
||||
result.push(cm);
|
||||
}
|
||||
if (shouldIncludeMessage(level, "error")) {
|
||||
const errors = await this.page.pageErrors({ filter: all ? "all" : "since-navigation" });
|
||||
for (const error of errors)
|
||||
result.push(pageErrorToConsoleMessage(error));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async clearConsoleMessages() {
|
||||
await this._initializedPromise;
|
||||
await Promise.all([
|
||||
this.page.clearConsoleMessages(),
|
||||
this.page.clearPageErrors()
|
||||
]);
|
||||
}
|
||||
async requests() {
|
||||
await this._initializedPromise;
|
||||
return this._requests;
|
||||
}
|
||||
async clearRequests() {
|
||||
await this._initializedPromise;
|
||||
this._requests.length = 0;
|
||||
}
|
||||
async captureSnapshot(selector, depth, relativeTo) {
|
||||
await this._initializedPromise;
|
||||
let tabSnapshot;
|
||||
const modalStates = await this._raceAgainstModalStates(async () => {
|
||||
const ariaSnapshot = selector ? await this.page.locator(selector).ariaSnapshot({ mode: "ai", depth }) : await this.page.ariaSnapshot({ mode: "ai", depth });
|
||||
tabSnapshot = {
|
||||
ariaSnapshot,
|
||||
modalStates: [],
|
||||
events: []
|
||||
};
|
||||
});
|
||||
if (tabSnapshot) {
|
||||
tabSnapshot.consoleLink = await this._consoleLog.take(relativeTo);
|
||||
tabSnapshot.events = this._recentEventEntries;
|
||||
this._recentEventEntries = [];
|
||||
}
|
||||
return tabSnapshot ?? {
|
||||
ariaSnapshot: "",
|
||||
modalStates,
|
||||
events: []
|
||||
};
|
||||
}
|
||||
_javaScriptBlocked() {
|
||||
return this._modalStates.some((state) => state.type === "dialog");
|
||||
}
|
||||
async _raceAgainstModalStates(action) {
|
||||
if (this.modalStates().length)
|
||||
return this.modalStates();
|
||||
const promise = new import_manualPromise.ManualPromise();
|
||||
const listener = (modalState) => promise.resolve([modalState]);
|
||||
this.once(TabEvents.modalState, listener);
|
||||
return await Promise.race([
|
||||
action().then(() => {
|
||||
this.off(TabEvents.modalState, listener);
|
||||
return [];
|
||||
}),
|
||||
promise
|
||||
]);
|
||||
}
|
||||
async waitForCompletion(callback) {
|
||||
await this._initializedPromise;
|
||||
await this._raceAgainstModalStates(() => (0, import_utils.waitForCompletion)(this, callback));
|
||||
}
|
||||
async refLocator(params) {
|
||||
await this._initializedPromise;
|
||||
return (await this.refLocators([params]))[0];
|
||||
}
|
||||
async refLocators(params) {
|
||||
await this._initializedPromise;
|
||||
return Promise.all(params.map(async (param) => {
|
||||
if (param.selector) {
|
||||
const selector = (0, import_locatorParser.locatorOrSelectorAsSelector)("javascript", param.selector, this.context.config.testIdAttribute || "data-testid");
|
||||
const handle = await this.page.$(selector);
|
||||
if (!handle)
|
||||
throw new Error(`"${param.selector}" does not match any elements.`);
|
||||
handle.dispose().catch(() => {
|
||||
});
|
||||
return { locator: this.page.locator(selector), resolved: (0, import_locatorGenerators.asLocator)("javascript", selector) };
|
||||
} else {
|
||||
try {
|
||||
let locator = this.page.locator(`aria-ref=${param.ref}`);
|
||||
if (param.element)
|
||||
locator = locator.describe(param.element);
|
||||
const resolved = await locator.normalize();
|
||||
return { locator, resolved: resolved.toString() };
|
||||
} catch (e) {
|
||||
throw new Error(`Ref ${param.ref} not found in the current page snapshot. Try capturing new snapshot.`);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
async waitForTimeout(time) {
|
||||
if (this._javaScriptBlocked()) {
|
||||
await new Promise((f) => setTimeout(f, time));
|
||||
return;
|
||||
}
|
||||
await this.page.evaluate(() => new Promise((f) => setTimeout(f, 1e3))).catch(() => {
|
||||
});
|
||||
}
|
||||
}
|
||||
function messageToConsoleMessage(message) {
|
||||
return {
|
||||
type: message.type(),
|
||||
timestamp: message.timestamp(),
|
||||
text: message.text(),
|
||||
toString: () => `[${message.type().toUpperCase()}] ${message.text()} @ ${message.location().url}:${message.location().lineNumber}`
|
||||
};
|
||||
}
|
||||
function pageErrorToConsoleMessage(errorOrValue) {
|
||||
if (errorOrValue instanceof Error) {
|
||||
return {
|
||||
type: "error",
|
||||
timestamp: Date.now(),
|
||||
text: errorOrValue.message,
|
||||
toString: () => errorOrValue.stack || errorOrValue.message
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "error",
|
||||
timestamp: Date.now(),
|
||||
text: String(errorOrValue),
|
||||
toString: () => String(errorOrValue)
|
||||
};
|
||||
}
|
||||
function renderModalStates(config, modalStates) {
|
||||
const result = [];
|
||||
if (modalStates.length === 0)
|
||||
result.push("- There is no modal state present");
|
||||
for (const state of modalStates)
|
||||
result.push(`- [${state.description}]: can be handled by ${config.skillMode ? state.clearedBy.skill : state.clearedBy.tool}`);
|
||||
return result;
|
||||
}
|
||||
const consoleMessageLevels = ["error", "warning", "info", "debug"];
|
||||
function shouldIncludeMessage(thresholdLevel, type) {
|
||||
const messageLevel = consoleLevelForMessageType(type);
|
||||
return consoleMessageLevels.indexOf(messageLevel) <= consoleMessageLevels.indexOf(thresholdLevel || "info");
|
||||
}
|
||||
function consoleLevelForMessageType(type) {
|
||||
switch (type) {
|
||||
case "assert":
|
||||
case "error":
|
||||
return "error";
|
||||
case "warning":
|
||||
return "warning";
|
||||
case "count":
|
||||
case "dir":
|
||||
case "dirxml":
|
||||
case "info":
|
||||
case "log":
|
||||
case "table":
|
||||
case "time":
|
||||
case "timeEnd":
|
||||
return "info";
|
||||
case "clear":
|
||||
case "debug":
|
||||
case "endGroup":
|
||||
case "profile":
|
||||
case "profileEnd":
|
||||
case "startGroup":
|
||||
case "startGroupCollapsed":
|
||||
case "trace":
|
||||
return "debug";
|
||||
default:
|
||||
return "info";
|
||||
}
|
||||
}
|
||||
const tabSymbol = Symbol("tabSymbol");
|
||||
function sanitizeForFilePath(s) {
|
||||
const sanitize = (s2) => s2.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, "-");
|
||||
const separator = s.lastIndexOf(".");
|
||||
if (separator === -1)
|
||||
return sanitize(s);
|
||||
return sanitize(s.substring(0, separator)) + "." + sanitize(s.substring(separator + 1));
|
||||
}
|
||||
function tabHeaderEquals(a, b) {
|
||||
return a.title === b.title && a.url === b.url && a.current === b.current && a.console.errors === b.console.errors && a.console.warnings === b.console.warnings && a.console.total === b.console.total;
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
Tab,
|
||||
renderModalStates,
|
||||
shouldIncludeMessage
|
||||
});
|
||||
67
node_modules/playwright-core/lib/tools/backend/tabs.js
generated
vendored
Normal file
67
node_modules/playwright-core/lib/tools/backend/tabs.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var tabs_exports = {};
|
||||
__export(tabs_exports, {
|
||||
default: () => tabs_default
|
||||
});
|
||||
module.exports = __toCommonJS(tabs_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
var import_response = require("./response");
|
||||
const browserTabs = (0, import_tool.defineTool)({
|
||||
capability: "core-tabs",
|
||||
schema: {
|
||||
name: "browser_tabs",
|
||||
title: "Manage tabs",
|
||||
description: "List, create, close, or select a browser tab.",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
action: import_zodBundle.z.enum(["list", "new", "close", "select"]).describe("Operation to perform"),
|
||||
index: import_zodBundle.z.number().optional().describe("Tab index, used for close/select. If omitted for close, current tab is closed.")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
switch (params.action) {
|
||||
case "list": {
|
||||
await context.ensureTab();
|
||||
break;
|
||||
}
|
||||
case "new": {
|
||||
await context.newTab();
|
||||
break;
|
||||
}
|
||||
case "close": {
|
||||
await context.closeTab(params.index);
|
||||
break;
|
||||
}
|
||||
case "select": {
|
||||
if (params.index === void 0)
|
||||
throw new Error("Tab index is required");
|
||||
await context.selectTab(params.index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const tabHeaders = await Promise.all(context.tabs().map((tab) => tab.headerSnapshot()));
|
||||
const result = (0, import_response.renderTabsMarkdown)(tabHeaders);
|
||||
response.addTextResult(result.join("\n"));
|
||||
}
|
||||
});
|
||||
var tabs_default = [
|
||||
browserTabs
|
||||
];
|
||||
47
node_modules/playwright-core/lib/tools/backend/tool.js
generated
vendored
Normal file
47
node_modules/playwright-core/lib/tools/backend/tool.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var tool_exports = {};
|
||||
__export(tool_exports, {
|
||||
defineTabTool: () => defineTabTool,
|
||||
defineTool: () => defineTool
|
||||
});
|
||||
module.exports = __toCommonJS(tool_exports);
|
||||
function defineTool(tool) {
|
||||
return tool;
|
||||
}
|
||||
function defineTabTool(tool) {
|
||||
return {
|
||||
...tool,
|
||||
handle: async (context, params, response) => {
|
||||
const tab = await context.ensureTab();
|
||||
const modalStates = tab.modalStates().map((state) => state.type);
|
||||
if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
|
||||
response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.`);
|
||||
else if (!tool.clearsModalState && modalStates.length)
|
||||
response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.`);
|
||||
else
|
||||
return tool.handle(tab, params, response);
|
||||
}
|
||||
};
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
defineTabTool,
|
||||
defineTool
|
||||
});
|
||||
102
node_modules/playwright-core/lib/tools/backend/tools.js
generated
vendored
Normal file
102
node_modules/playwright-core/lib/tools/backend/tools.js
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var tools_exports = {};
|
||||
__export(tools_exports, {
|
||||
browserTools: () => browserTools,
|
||||
filteredTools: () => filteredTools
|
||||
});
|
||||
module.exports = __toCommonJS(tools_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_common = __toESM(require("./common"));
|
||||
var import_config = __toESM(require("./config"));
|
||||
var import_console = __toESM(require("./console"));
|
||||
var import_cookies = __toESM(require("./cookies"));
|
||||
var import_devtools = __toESM(require("./devtools"));
|
||||
var import_dialogs = __toESM(require("./dialogs"));
|
||||
var import_evaluate = __toESM(require("./evaluate"));
|
||||
var import_files = __toESM(require("./files"));
|
||||
var import_form = __toESM(require("./form"));
|
||||
var import_keyboard = __toESM(require("./keyboard"));
|
||||
var import_mouse = __toESM(require("./mouse"));
|
||||
var import_navigate = __toESM(require("./navigate"));
|
||||
var import_network = __toESM(require("./network"));
|
||||
var import_pdf = __toESM(require("./pdf"));
|
||||
var import_route = __toESM(require("./route"));
|
||||
var import_runCode = __toESM(require("./runCode"));
|
||||
var import_snapshot = __toESM(require("./snapshot"));
|
||||
var import_screenshot = __toESM(require("./screenshot"));
|
||||
var import_storage = __toESM(require("./storage"));
|
||||
var import_tabs = __toESM(require("./tabs"));
|
||||
var import_tracing = __toESM(require("./tracing"));
|
||||
var import_verify = __toESM(require("./verify"));
|
||||
var import_video = __toESM(require("./video"));
|
||||
var import_wait = __toESM(require("./wait"));
|
||||
var import_webstorage = __toESM(require("./webstorage"));
|
||||
const browserTools = [
|
||||
...import_common.default,
|
||||
...import_config.default,
|
||||
...import_console.default,
|
||||
...import_cookies.default,
|
||||
...import_devtools.default,
|
||||
...import_dialogs.default,
|
||||
...import_evaluate.default,
|
||||
...import_files.default,
|
||||
...import_form.default,
|
||||
...import_keyboard.default,
|
||||
...import_mouse.default,
|
||||
...import_navigate.default,
|
||||
...import_network.default,
|
||||
...import_pdf.default,
|
||||
...import_route.default,
|
||||
...import_runCode.default,
|
||||
...import_screenshot.default,
|
||||
...import_snapshot.default,
|
||||
...import_storage.default,
|
||||
...import_tabs.default,
|
||||
...import_tracing.default,
|
||||
...import_verify.default,
|
||||
...import_video.default,
|
||||
...import_wait.default,
|
||||
...import_webstorage.default
|
||||
];
|
||||
function filteredTools(config2) {
|
||||
return browserTools.filter((tool) => tool.capability.startsWith("core") || config2.capabilities?.includes(tool.capability)).filter((tool) => !tool.skillOnly).map((tool) => ({
|
||||
...tool,
|
||||
schema: {
|
||||
...tool.schema,
|
||||
// Note: we first ensure that "selector" property is present, so that we can omit() it without an error.
|
||||
inputSchema: tool.schema.inputSchema.extend({ selector: import_zodBundle.z.string(), startSelector: import_zodBundle.z.string(), endSelector: import_zodBundle.z.string() }).omit({ selector: true, startSelector: true, endSelector: true })
|
||||
}
|
||||
}));
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
browserTools,
|
||||
filteredTools
|
||||
});
|
||||
78
node_modules/playwright-core/lib/tools/backend/tracing.js
generated
vendored
Normal file
78
node_modules/playwright-core/lib/tools/backend/tracing.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var tracing_exports = {};
|
||||
__export(tracing_exports, {
|
||||
default: () => tracing_default
|
||||
});
|
||||
module.exports = __toCommonJS(tracing_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const tracingStart = (0, import_tool.defineTool)({
|
||||
capability: "devtools",
|
||||
schema: {
|
||||
name: "browser_start_tracing",
|
||||
title: "Start tracing",
|
||||
description: "Start trace recording",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
const tracesDir = await context.outputFile({ prefix: "", suggestedFilename: `traces`, ext: "" }, { origin: "code" });
|
||||
const name = "trace-" + Date.now();
|
||||
await browserContext.tracing.start({
|
||||
name,
|
||||
screenshots: true,
|
||||
snapshots: true,
|
||||
live: true
|
||||
});
|
||||
response.addTextResult(`Trace recording started`);
|
||||
response.addFileLink("Action log", `${tracesDir}/${name}.trace`);
|
||||
response.addFileLink("Network log", `${tracesDir}/${name}.network`);
|
||||
response.addFileLink("Resources", `${tracesDir}/resources`);
|
||||
browserContext.tracing[traceLegendSymbol] = { tracesDir, name };
|
||||
}
|
||||
});
|
||||
const tracingStop = (0, import_tool.defineTool)({
|
||||
capability: "devtools",
|
||||
schema: {
|
||||
name: "browser_stop_tracing",
|
||||
title: "Stop tracing",
|
||||
description: "Stop trace recording",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const browserContext = await context.ensureBrowserContext();
|
||||
await browserContext.tracing.stop();
|
||||
const traceLegend = browserContext.tracing[traceLegendSymbol];
|
||||
if (!traceLegend)
|
||||
throw new Error("Tracing is not started");
|
||||
delete browserContext.tracing[traceLegendSymbol];
|
||||
response.addTextResult(`Trace recording stopped.`);
|
||||
response.addFileLink("Trace", `${traceLegend.tracesDir}/${traceLegend.name}.trace`);
|
||||
response.addFileLink("Network log", `${traceLegend.tracesDir}/${traceLegend.name}.network`);
|
||||
response.addFileLink("Resources", `${traceLegend.tracesDir}/resources`);
|
||||
}
|
||||
});
|
||||
var tracing_default = [
|
||||
tracingStart,
|
||||
tracingStop
|
||||
];
|
||||
const traceLegendSymbol = Symbol("tracesDir");
|
||||
83
node_modules/playwright-core/lib/tools/backend/utils.js
generated
vendored
Normal file
83
node_modules/playwright-core/lib/tools/backend/utils.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var utils_exports = {};
|
||||
__export(utils_exports, {
|
||||
eventWaiter: () => eventWaiter,
|
||||
waitForCompletion: () => waitForCompletion
|
||||
});
|
||||
module.exports = __toCommonJS(utils_exports);
|
||||
async function waitForCompletion(tab, callback) {
|
||||
const requests = [];
|
||||
const requestListener = (request) => requests.push(request);
|
||||
const disposeListeners = () => {
|
||||
tab.page.off("request", requestListener);
|
||||
};
|
||||
tab.page.on("request", requestListener);
|
||||
let result;
|
||||
try {
|
||||
result = await callback();
|
||||
await tab.waitForTimeout(500);
|
||||
} finally {
|
||||
disposeListeners();
|
||||
}
|
||||
const requestedNavigation = requests.some((request) => request.isNavigationRequest());
|
||||
if (requestedNavigation) {
|
||||
await tab.page.mainFrame().waitForLoadState("load", { timeout: 1e4 }).catch(() => {
|
||||
});
|
||||
return result;
|
||||
}
|
||||
const promises = [];
|
||||
for (const request of requests) {
|
||||
if (["document", "stylesheet", "script", "xhr", "fetch"].includes(request.resourceType()))
|
||||
promises.push(request.response().then((r) => r?.finished()).catch(() => {
|
||||
}));
|
||||
else
|
||||
promises.push(request.response().catch(() => {
|
||||
}));
|
||||
}
|
||||
const timeout = new Promise((resolve) => setTimeout(resolve, 5e3));
|
||||
await Promise.race([Promise.all(promises), timeout]);
|
||||
if (requests.length)
|
||||
await tab.waitForTimeout(500);
|
||||
return result;
|
||||
}
|
||||
function eventWaiter(page, event, timeout) {
|
||||
const disposables = [];
|
||||
const eventPromise = new Promise((resolve, reject) => {
|
||||
page.on(event, resolve);
|
||||
disposables.push(() => page.off(event, resolve));
|
||||
});
|
||||
let abort;
|
||||
const abortPromise = new Promise((resolve, reject) => {
|
||||
abort = () => resolve(void 0);
|
||||
});
|
||||
const timeoutPromise = new Promise((f) => {
|
||||
const timeoutId = setTimeout(() => f(void 0), timeout);
|
||||
disposables.push(() => clearTimeout(timeoutId));
|
||||
});
|
||||
return {
|
||||
promise: Promise.race([eventPromise, abortPromise, timeoutPromise]).finally(() => disposables.forEach((dispose) => dispose())),
|
||||
abort
|
||||
};
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
eventWaiter,
|
||||
waitForCompletion
|
||||
});
|
||||
151
node_modules/playwright-core/lib/tools/backend/verify.js
generated
vendored
Normal file
151
node_modules/playwright-core/lib/tools/backend/verify.js
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var verify_exports = {};
|
||||
__export(verify_exports, {
|
||||
default: () => verify_default
|
||||
});
|
||||
module.exports = __toCommonJS(verify_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_stringUtils = require("../../utils/isomorphic/stringUtils");
|
||||
var import_tool = require("./tool");
|
||||
const verifyElement = (0, import_tool.defineTabTool)({
|
||||
capability: "testing",
|
||||
schema: {
|
||||
name: "browser_verify_element_visible",
|
||||
title: "Verify element visible",
|
||||
description: "Verify element is visible on the page",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
role: import_zodBundle.z.string().describe('ROLE of the element. Can be found in the snapshot like this: `- {ROLE} "Accessible Name":`'),
|
||||
accessibleName: import_zodBundle.z.string().describe('ACCESSIBLE_NAME of the element. Can be found in the snapshot like this: `- role "{ACCESSIBLE_NAME}"`')
|
||||
}),
|
||||
type: "assertion"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
for (const frame of tab.page.frames()) {
|
||||
const locator = frame.getByRole(params.role, { name: params.accessibleName });
|
||||
if (await locator.count() > 0) {
|
||||
const resolved = await locator.normalize();
|
||||
response.addCode(`await expect(page.${resolved}).toBeVisible();`);
|
||||
response.addTextResult("Done");
|
||||
return;
|
||||
}
|
||||
}
|
||||
response.addError(`Element with role "${params.role}" and accessible name "${params.accessibleName}" not found`);
|
||||
}
|
||||
});
|
||||
const verifyText = (0, import_tool.defineTabTool)({
|
||||
capability: "testing",
|
||||
schema: {
|
||||
name: "browser_verify_text_visible",
|
||||
title: "Verify text visible",
|
||||
description: `Verify text is visible on the page. Prefer ${verifyElement.schema.name} if possible.`,
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
text: import_zodBundle.z.string().describe('TEXT to verify. Can be found in the snapshot like this: `- role "Accessible Name": {TEXT}` or like this: `- text: {TEXT}`')
|
||||
}),
|
||||
type: "assertion"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
for (const frame of tab.page.frames()) {
|
||||
const locator = frame.getByText(params.text).filter({ visible: true });
|
||||
if (await locator.count() > 0) {
|
||||
const resolved = await locator.normalize();
|
||||
response.addCode(`await expect(page.${resolved}).toBeVisible();`);
|
||||
response.addTextResult("Done");
|
||||
return;
|
||||
}
|
||||
}
|
||||
response.addError("Text not found");
|
||||
}
|
||||
});
|
||||
const verifyList = (0, import_tool.defineTabTool)({
|
||||
capability: "testing",
|
||||
schema: {
|
||||
name: "browser_verify_list_visible",
|
||||
title: "Verify list visible",
|
||||
description: "Verify list is visible on the page",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
element: import_zodBundle.z.string().describe("Human-readable list description"),
|
||||
ref: import_zodBundle.z.string().describe("Exact target element reference that points to the list"),
|
||||
selector: import_zodBundle.z.string().optional().describe('CSS or role selector for the target list, when "ref" is not available.'),
|
||||
items: import_zodBundle.z.array(import_zodBundle.z.string()).describe("Items to verify")
|
||||
}),
|
||||
type: "assertion"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const { locator } = await tab.refLocator({ ref: params.ref, selector: params.selector, element: params.element });
|
||||
const itemTexts = [];
|
||||
for (const item of params.items) {
|
||||
const itemLocator = locator.getByText(item);
|
||||
if (await itemLocator.count() === 0) {
|
||||
response.addError(`Item "${item}" not found`);
|
||||
return;
|
||||
}
|
||||
itemTexts.push(await itemLocator.textContent(tab.expectTimeoutOptions));
|
||||
}
|
||||
const ariaSnapshot = `\`
|
||||
- list:
|
||||
${itemTexts.map((t) => ` - listitem: ${(0, import_stringUtils.escapeWithQuotes)(t, '"')}`).join("\n")}
|
||||
\``;
|
||||
response.addCode(`await expect(page.locator('body')).toMatchAriaSnapshot(${ariaSnapshot});`);
|
||||
response.addTextResult("Done");
|
||||
}
|
||||
});
|
||||
const verifyValue = (0, import_tool.defineTabTool)({
|
||||
capability: "testing",
|
||||
schema: {
|
||||
name: "browser_verify_value",
|
||||
title: "Verify value",
|
||||
description: "Verify element value",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
type: import_zodBundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the element"),
|
||||
element: import_zodBundle.z.string().describe("Human-readable element description"),
|
||||
ref: import_zodBundle.z.string().describe("Exact target element reference from the page snapshot"),
|
||||
selector: import_zodBundle.z.string().optional().describe('CSS or role selector for the target element, when "ref" is not available'),
|
||||
value: import_zodBundle.z.string().describe('Value to verify. For checkbox, use "true" or "false".')
|
||||
}),
|
||||
type: "assertion"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const { locator, resolved } = await tab.refLocator({ ref: params.ref, selector: params.selector, element: params.element });
|
||||
const locatorSource = `page.${resolved}`;
|
||||
if (params.type === "textbox" || params.type === "slider" || params.type === "combobox") {
|
||||
const value = await locator.inputValue(tab.expectTimeoutOptions);
|
||||
if (value !== params.value) {
|
||||
response.addError(`Expected value "${params.value}", but got "${value}"`);
|
||||
return;
|
||||
}
|
||||
response.addCode(`await expect(${locatorSource}).toHaveValue(${(0, import_stringUtils.escapeWithQuotes)(params.value)});`);
|
||||
} else if (params.type === "checkbox" || params.type === "radio") {
|
||||
const value = await locator.isChecked(tab.expectTimeoutOptions);
|
||||
if (value !== (params.value === "true")) {
|
||||
response.addError(`Expected value "${params.value}", but got "${value}"`);
|
||||
return;
|
||||
}
|
||||
const matcher = value ? "toBeChecked" : "not.toBeChecked";
|
||||
response.addCode(`await expect(${locatorSource}).${matcher}();`);
|
||||
}
|
||||
response.addTextResult("Done");
|
||||
}
|
||||
});
|
||||
var verify_default = [
|
||||
verifyElement,
|
||||
verifyText,
|
||||
verifyList,
|
||||
verifyValue
|
||||
];
|
||||
98
node_modules/playwright-core/lib/tools/backend/video.js
generated
vendored
Normal file
98
node_modules/playwright-core/lib/tools/backend/video.js
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var video_exports = {};
|
||||
__export(video_exports, {
|
||||
default: () => video_default
|
||||
});
|
||||
module.exports = __toCommonJS(video_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const videoStart = (0, import_tool.defineTool)({
|
||||
capability: "devtools",
|
||||
schema: {
|
||||
name: "browser_start_video",
|
||||
title: "Start video",
|
||||
description: "Start video recording",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
filename: import_zodBundle.z.string().optional().describe("Filename to save the video."),
|
||||
size: import_zodBundle.z.object({
|
||||
width: import_zodBundle.z.number().describe("Video width"),
|
||||
height: import_zodBundle.z.number().describe("Video height")
|
||||
}).optional().describe("Video size")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const resolvedFile = await response.resolveClientFile({ prefix: "video", ext: "webm", suggestedFilename: params.filename }, "Video");
|
||||
await context.startVideoRecording(resolvedFile.fileName, { size: params.size });
|
||||
response.addTextResult("Video recording started.");
|
||||
}
|
||||
});
|
||||
const videoStop = (0, import_tool.defineTool)({
|
||||
capability: "devtools",
|
||||
schema: {
|
||||
name: "browser_stop_video",
|
||||
title: "Stop video",
|
||||
description: "Stop video recording",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const fileNames = await context.stopVideoRecording();
|
||||
if (!fileNames.length) {
|
||||
response.addTextResult("No videos were recorded.");
|
||||
return;
|
||||
}
|
||||
for (const fileName of fileNames) {
|
||||
const resolvedFile = await response.resolveClientFile({
|
||||
prefix: "video",
|
||||
ext: "webm",
|
||||
suggestedFilename: fileName
|
||||
}, "Video");
|
||||
await response.addFileResult(resolvedFile, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
const videoChapter = (0, import_tool.defineTool)({
|
||||
capability: "devtools",
|
||||
schema: {
|
||||
name: "browser_video_chapter",
|
||||
title: "Video chapter",
|
||||
description: "Add a chapter marker to the video recording. Shows a full-screen chapter card with blurred backdrop.",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
title: import_zodBundle.z.string().describe("Chapter title"),
|
||||
description: import_zodBundle.z.string().optional().describe("Chapter description"),
|
||||
duration: import_zodBundle.z.number().optional().describe("Duration in milliseconds to show the chapter card")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
const tab = context.currentTabOrDie();
|
||||
await tab.page.screencast.showChapter(params.title, {
|
||||
description: params.description,
|
||||
duration: params.duration
|
||||
});
|
||||
response.addTextResult(`Chapter '${params.title}' added.`);
|
||||
}
|
||||
});
|
||||
var video_default = [
|
||||
videoStart,
|
||||
videoStop,
|
||||
videoChapter
|
||||
];
|
||||
63
node_modules/playwright-core/lib/tools/backend/wait.js
generated
vendored
Normal file
63
node_modules/playwright-core/lib/tools/backend/wait.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var wait_exports = {};
|
||||
__export(wait_exports, {
|
||||
default: () => wait_default
|
||||
});
|
||||
module.exports = __toCommonJS(wait_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const wait = (0, import_tool.defineTool)({
|
||||
capability: "core",
|
||||
schema: {
|
||||
name: "browser_wait_for",
|
||||
title: "Wait for",
|
||||
description: "Wait for text to appear or disappear or a specified time to pass",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
time: import_zodBundle.z.number().optional().describe("The time to wait in seconds"),
|
||||
text: import_zodBundle.z.string().optional().describe("The text to wait for"),
|
||||
textGone: import_zodBundle.z.string().optional().describe("The text to wait for to disappear")
|
||||
}),
|
||||
type: "assertion"
|
||||
},
|
||||
handle: async (context, params, response) => {
|
||||
if (!params.text && !params.textGone && !params.time)
|
||||
throw new Error("Either time, text or textGone must be provided");
|
||||
if (params.time) {
|
||||
response.addCode(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
|
||||
await new Promise((f) => setTimeout(f, Math.min(3e4, params.time * 1e3)));
|
||||
}
|
||||
const tab = context.currentTabOrDie();
|
||||
const locator = params.text ? tab.page.getByText(params.text).first() : void 0;
|
||||
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : void 0;
|
||||
if (goneLocator) {
|
||||
response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
|
||||
await goneLocator.waitFor({ state: "hidden" });
|
||||
}
|
||||
if (locator) {
|
||||
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
||||
await locator.waitFor({ state: "visible" });
|
||||
}
|
||||
response.addTextResult(`Waited for ${params.text || params.textGone || params.time}`);
|
||||
response.setIncludeSnapshot();
|
||||
}
|
||||
});
|
||||
var wait_default = [
|
||||
wait
|
||||
];
|
||||
223
node_modules/playwright-core/lib/tools/backend/webstorage.js
generated
vendored
Normal file
223
node_modules/playwright-core/lib/tools/backend/webstorage.js
generated
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var webstorage_exports = {};
|
||||
__export(webstorage_exports, {
|
||||
default: () => webstorage_default
|
||||
});
|
||||
module.exports = __toCommonJS(webstorage_exports);
|
||||
var import_zodBundle = require("../../zodBundle");
|
||||
var import_tool = require("./tool");
|
||||
const localStorageList = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_localstorage_list",
|
||||
title: "List localStorage",
|
||||
description: "List all localStorage key-value pairs",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const items = await tab.page.evaluate(() => {
|
||||
const result = [];
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key !== null)
|
||||
result.push({ key, value: localStorage.getItem(key) || "" });
|
||||
}
|
||||
return result;
|
||||
});
|
||||
if (items.length === 0)
|
||||
response.addTextResult("No localStorage items found");
|
||||
else
|
||||
response.addTextResult(items.map((item) => `${item.key}=${item.value}`).join("\n"));
|
||||
response.addCode(`await page.evaluate(() => ({ ...localStorage }));`);
|
||||
}
|
||||
});
|
||||
const localStorageGet = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_localstorage_get",
|
||||
title: "Get localStorage item",
|
||||
description: "Get a localStorage item by key",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Key to get")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const value = await tab.page.evaluate((key) => localStorage.getItem(key), params.key);
|
||||
if (value === null)
|
||||
response.addTextResult(`localStorage key '${params.key}' not found`);
|
||||
else
|
||||
response.addTextResult(`${params.key}=${value}`);
|
||||
response.addCode(`await page.evaluate(() => localStorage.getItem('${params.key}'));`);
|
||||
}
|
||||
});
|
||||
const localStorageSet = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_localstorage_set",
|
||||
title: "Set localStorage item",
|
||||
description: "Set a localStorage item",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Key to set"),
|
||||
value: import_zodBundle.z.string().describe("Value to set")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.evaluate(({ key, value }) => localStorage.setItem(key, value), params);
|
||||
response.addCode(`await page.evaluate(() => localStorage.setItem('${params.key}', '${params.value}'));`);
|
||||
}
|
||||
});
|
||||
const localStorageDelete = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_localstorage_delete",
|
||||
title: "Delete localStorage item",
|
||||
description: "Delete a localStorage item",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Key to delete")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.evaluate((key) => localStorage.removeItem(key), params.key);
|
||||
response.addCode(`await page.evaluate(() => localStorage.removeItem('${params.key}'));`);
|
||||
}
|
||||
});
|
||||
const localStorageClear = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_localstorage_clear",
|
||||
title: "Clear localStorage",
|
||||
description: "Clear all localStorage",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.evaluate(() => localStorage.clear());
|
||||
response.addCode(`await page.evaluate(() => localStorage.clear());`);
|
||||
}
|
||||
});
|
||||
const sessionStorageList = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_sessionstorage_list",
|
||||
title: "List sessionStorage",
|
||||
description: "List all sessionStorage key-value pairs",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const items = await tab.page.evaluate(() => {
|
||||
const result = [];
|
||||
for (let i = 0; i < sessionStorage.length; i++) {
|
||||
const key = sessionStorage.key(i);
|
||||
if (key !== null)
|
||||
result.push({ key, value: sessionStorage.getItem(key) || "" });
|
||||
}
|
||||
return result;
|
||||
});
|
||||
if (items.length === 0)
|
||||
response.addTextResult("No sessionStorage items found");
|
||||
else
|
||||
response.addTextResult(items.map((item) => `${item.key}=${item.value}`).join("\n"));
|
||||
response.addCode(`await page.evaluate(() => ({ ...sessionStorage }));`);
|
||||
}
|
||||
});
|
||||
const sessionStorageGet = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_sessionstorage_get",
|
||||
title: "Get sessionStorage item",
|
||||
description: "Get a sessionStorage item by key",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Key to get")
|
||||
}),
|
||||
type: "readOnly"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
const value = await tab.page.evaluate((key) => sessionStorage.getItem(key), params.key);
|
||||
if (value === null)
|
||||
response.addTextResult(`sessionStorage key '${params.key}' not found`);
|
||||
else
|
||||
response.addTextResult(`${params.key}=${value}`);
|
||||
response.addCode(`await page.evaluate(() => sessionStorage.getItem('${params.key}'));`);
|
||||
}
|
||||
});
|
||||
const sessionStorageSet = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_sessionstorage_set",
|
||||
title: "Set sessionStorage item",
|
||||
description: "Set a sessionStorage item",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Key to set"),
|
||||
value: import_zodBundle.z.string().describe("Value to set")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.evaluate(({ key, value }) => sessionStorage.setItem(key, value), params);
|
||||
response.addCode(`await page.evaluate(() => sessionStorage.setItem('${params.key}', '${params.value}'));`);
|
||||
}
|
||||
});
|
||||
const sessionStorageDelete = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_sessionstorage_delete",
|
||||
title: "Delete sessionStorage item",
|
||||
description: "Delete a sessionStorage item",
|
||||
inputSchema: import_zodBundle.z.object({
|
||||
key: import_zodBundle.z.string().describe("Key to delete")
|
||||
}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.evaluate((key) => sessionStorage.removeItem(key), params.key);
|
||||
response.addCode(`await page.evaluate(() => sessionStorage.removeItem('${params.key}'));`);
|
||||
}
|
||||
});
|
||||
const sessionStorageClear = (0, import_tool.defineTabTool)({
|
||||
capability: "storage",
|
||||
schema: {
|
||||
name: "browser_sessionstorage_clear",
|
||||
title: "Clear sessionStorage",
|
||||
description: "Clear all sessionStorage",
|
||||
inputSchema: import_zodBundle.z.object({}),
|
||||
type: "action"
|
||||
},
|
||||
handle: async (tab, params, response) => {
|
||||
await tab.page.evaluate(() => sessionStorage.clear());
|
||||
response.addCode(`await page.evaluate(() => sessionStorage.clear());`);
|
||||
}
|
||||
});
|
||||
var webstorage_default = [
|
||||
localStorageList,
|
||||
localStorageGet,
|
||||
localStorageSet,
|
||||
localStorageDelete,
|
||||
localStorageClear,
|
||||
sessionStorageList,
|
||||
sessionStorageGet,
|
||||
sessionStorageSet,
|
||||
sessionStorageDelete,
|
||||
sessionStorageClear
|
||||
];
|
||||
Reference in New Issue
Block a user