@wordbricks/playwright-mcp 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.d.ts +1 -1
- package/index.d.ts +1 -1
- package/lib/browserContextFactory.js +36 -1
- package/lib/config.js +4 -6
- package/lib/extension/extensionContextFactory.js +1 -1
- package/package.json +7 -8
- package/src/index.ts +1 -1
package/config.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
19
19
|
import type { Config } from './config.js';
|
|
20
|
-
import type { BrowserContext } from 'playwright';
|
|
20
|
+
import type { BrowserContext } from 'playwright-core';
|
|
21
21
|
|
|
22
22
|
export declare function createConnection(config?: Config, contextGetter?: () => Promise<BrowserContext>): Promise<Server>;
|
|
23
23
|
export {};
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import fs from 'fs';
|
|
17
17
|
import net from 'net';
|
|
18
18
|
import path from 'path';
|
|
19
|
-
import * as playwright from 'playwright';
|
|
19
|
+
import * as playwright from 'playwright-core';
|
|
20
20
|
import ms from 'ms';
|
|
21
21
|
// @ts-ignore
|
|
22
22
|
import { registryDirectory } from 'playwright-core/lib/server/registry/index';
|
|
@@ -33,6 +33,37 @@ async function applyInitScript(browserContext, config) {
|
|
|
33
33
|
await browserContext.addInitScript(scriptContent);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
async function hidePlaywrightMarkers(browserContext) {
|
|
37
|
+
await browserContext.addInitScript(() => {
|
|
38
|
+
// Delete the property if it exists
|
|
39
|
+
delete window.__pwInitScripts;
|
|
40
|
+
// Redefine `Object.getOwnPropertyNames`
|
|
41
|
+
const originalGetOwnPropertyNames = Object.getOwnPropertyNames;
|
|
42
|
+
Object.getOwnPropertyNames = (obj) => {
|
|
43
|
+
const props = originalGetOwnPropertyNames(obj);
|
|
44
|
+
return props.filter((prop) => prop !== '__pwInitScripts');
|
|
45
|
+
};
|
|
46
|
+
// Use a Proxy to handle access to `window`
|
|
47
|
+
const windowHandler = {
|
|
48
|
+
get(target, prop) {
|
|
49
|
+
if (prop === '__pwInitScripts')
|
|
50
|
+
return undefined; // Hide the property
|
|
51
|
+
return Reflect.get(target, prop);
|
|
52
|
+
},
|
|
53
|
+
has(target, prop) {
|
|
54
|
+
if (prop === '__pwInitScripts')
|
|
55
|
+
return false; // Prevent detection via "in" operator
|
|
56
|
+
return Reflect.has(target, prop);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const proxiedWindow = new Proxy(window, windowHandler);
|
|
60
|
+
Object.defineProperty(globalThis, 'window', {
|
|
61
|
+
value: proxiedWindow,
|
|
62
|
+
configurable: false,
|
|
63
|
+
writable: false,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
36
67
|
export function contextFactory(config) {
|
|
37
68
|
if (config.browser.remoteEndpoint)
|
|
38
69
|
return new RemoteContextFactory(config);
|
|
@@ -146,6 +177,7 @@ class IsolatedContextFactory extends BaseContextFactory {
|
|
|
146
177
|
async _doCreateContext(browser) {
|
|
147
178
|
const browserContext = await browser.newContext(this.config.browser.contextOptions);
|
|
148
179
|
await applyInitScript(browserContext, this.config);
|
|
180
|
+
await hidePlaywrightMarkers(browserContext);
|
|
149
181
|
return browserContext;
|
|
150
182
|
}
|
|
151
183
|
}
|
|
@@ -159,6 +191,7 @@ class CdpContextFactory extends BaseContextFactory {
|
|
|
159
191
|
async _doCreateContext(browser) {
|
|
160
192
|
const browserContext = this.config.browser.isolated ? await browser.newContext() : browser.contexts()[0];
|
|
161
193
|
await applyInitScript(browserContext, this.config);
|
|
194
|
+
await hidePlaywrightMarkers(browserContext);
|
|
162
195
|
return browserContext;
|
|
163
196
|
}
|
|
164
197
|
}
|
|
@@ -176,6 +209,7 @@ class RemoteContextFactory extends BaseContextFactory {
|
|
|
176
209
|
async _doCreateContext(browser) {
|
|
177
210
|
const browserContext = await browser.newContext();
|
|
178
211
|
await applyInitScript(browserContext, this.config);
|
|
212
|
+
await hidePlaywrightMarkers(browserContext);
|
|
179
213
|
return browserContext;
|
|
180
214
|
}
|
|
181
215
|
}
|
|
@@ -212,6 +246,7 @@ class PersistentContextFactory {
|
|
|
212
246
|
args,
|
|
213
247
|
});
|
|
214
248
|
await applyInitScript(browserContext, this.config);
|
|
249
|
+
await hidePlaywrightMarkers(browserContext);
|
|
215
250
|
// Start auto-close timer
|
|
216
251
|
this._startAutoCloseTimer(browserContext);
|
|
217
252
|
const close = () => this._closeBrowserContext(browserContext, userDataDir);
|
package/lib/config.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import fs from 'fs';
|
|
17
17
|
import os from 'os';
|
|
18
18
|
import path from 'path';
|
|
19
|
-
import { devices } from 'playwright';
|
|
19
|
+
import { devices } from 'playwright-core';
|
|
20
20
|
import { sanitizeForFilePath } from './utils/fileUtils.js';
|
|
21
21
|
const defaultConfig = {
|
|
22
22
|
browser: {
|
|
@@ -83,11 +83,9 @@ export function configFromCLIOptions(cliOptions) {
|
|
|
83
83
|
if (cliOptions.sandbox === false)
|
|
84
84
|
launchOptions.chromiumSandbox = false;
|
|
85
85
|
// Add default Chrome args to avoid automation detection
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
launchOptions.args.push('--disable-blink-features=AutomationControlled');
|
|
90
|
-
}
|
|
86
|
+
launchOptions.args = launchOptions.args || [];
|
|
87
|
+
launchOptions.args.push('--disable-infobars');
|
|
88
|
+
launchOptions.args.push('--disable-blink-features=AutomationControlled');
|
|
91
89
|
// --app was passed, add app mode argument
|
|
92
90
|
if (cliOptions.app) {
|
|
93
91
|
launchOptions.args = launchOptions.args || [];
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import debug from 'debug';
|
|
17
|
-
import * as playwright from 'playwright';
|
|
17
|
+
import * as playwright from 'playwright-core';
|
|
18
18
|
import { startHttpServer } from '../utils/httpServer.js';
|
|
19
19
|
import { CDPRelayServer } from './cdpRelay.js';
|
|
20
20
|
const debugLogger = debug('pw:mcp:relay');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordbricks/playwright-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Playwright Tools for MCP",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"build": "tsc",
|
|
20
20
|
"build:extension": "tsc --project extension",
|
|
21
21
|
"dev": "concurrently --raw prefix none \"tsc --watch\" \"DEBUG=pw:mcp:* node --watch=lib cli.js --port 9224\"",
|
|
22
|
-
"dev:isolated": "concurrently --raw prefix none \"tsc --watch\" \"DEBUG=pw:mcp:* node --watch=lib cli.js --port 9224 --isolated
|
|
23
|
-
"dev:isolated:headless": "concurrently --raw prefix none \"tsc --watch\" \"DEBUG=pw:mcp:* node --watch=lib cli.js --port 9224 --isolated --headless
|
|
22
|
+
"dev:isolated": "concurrently --raw prefix none \"tsc --watch\" \"DEBUG=pw:mcp:* node --watch=lib cli.js --port 9224 --isolated\"",
|
|
23
|
+
"dev:isolated:headless": "concurrently --raw prefix none \"tsc --watch\" \"DEBUG=pw:mcp:* node --watch=lib cli.js --port 9224 --isolated --headless\"",
|
|
24
24
|
"dev:vision": "concurrently --raw prefix none \"tsc --watch\" \"DEBUG=pw:mcp:* node --watch=lib cli.js --port 9224 --caps=vision\"",
|
|
25
|
-
"start": "node cli.js --port 9224
|
|
26
|
-
"start:isolated": "node cli.js --port 9224 --
|
|
27
|
-
"start:vision": "node cli.js --port 9224 --
|
|
25
|
+
"start": "node cli.js --port 9224",
|
|
26
|
+
"start:isolated": "node cli.js --port 9224 --isolated",
|
|
27
|
+
"start:vision": "node cli.js --port 9224 --caps=vision",
|
|
28
28
|
"lint": "npm run update-readme && npm run check-deps && eslint . && tsc --noEmit",
|
|
29
29
|
"lint-fix": "eslint . --fix",
|
|
30
30
|
"check-deps": "node utils/check-deps.js",
|
|
@@ -60,8 +60,7 @@
|
|
|
60
60
|
"lodash": "^4.17.21",
|
|
61
61
|
"mime": "^4.0.7",
|
|
62
62
|
"ms": "^2.1.3",
|
|
63
|
-
"playwright": "npm:rebrowser-playwright@1.52.0",
|
|
64
|
-
"playwright-core": "1.52.0",
|
|
63
|
+
"playwright-core": "npm:rebrowser-playwright-core@1.52.0",
|
|
65
64
|
"raw-body": "^3.0.0",
|
|
66
65
|
"typescript-parsec": "0.3.4",
|
|
67
66
|
"ws": "^8.18.1",
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { contextFactory } from './browserContextFactory.js';
|
|
|
20
20
|
import * as mcpServer from './mcp/server.js';
|
|
21
21
|
|
|
22
22
|
import type { Config } from '../config.js';
|
|
23
|
-
import type { BrowserContext } from 'playwright';
|
|
23
|
+
import type { BrowserContext } from 'playwright-core';
|
|
24
24
|
import type { BrowserContextFactory } from './browserContextFactory.js';
|
|
25
25
|
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
26
26
|
|