got trade working
This commit is contained in:
parent
dcbeebac83
commit
12dcf0776a
3 changed files with 17 additions and 58 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { chromium } from "playwright";
|
||||
import { chromium } from "patchright";
|
||||
import { createInterface } from "readline";
|
||||
|
||||
// All logging goes to stderr — never corrupt the JSON protocol on stdout
|
||||
|
|
@ -21,36 +21,6 @@ function sendEvent(event, data = {}) {
|
|||
sendJson({ type: "event", event, ...data });
|
||||
}
|
||||
|
||||
// --- Stealth script (same as the working TS version) ---
|
||||
const STEALTH_SCRIPT = `
|
||||
Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
|
||||
|
||||
Object.defineProperty(navigator, 'plugins', {
|
||||
get: () => [
|
||||
{ name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer' },
|
||||
{ name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai' },
|
||||
{ name: 'Native Client', filename: 'internal-nacl-plugin' },
|
||||
],
|
||||
});
|
||||
|
||||
Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] });
|
||||
|
||||
delete window.__playwright;
|
||||
delete window.__pw_manual;
|
||||
|
||||
if (!window.chrome) window.chrome = {};
|
||||
if (!window.chrome.runtime) window.chrome.runtime = { id: undefined };
|
||||
|
||||
const originalQuery = window.navigator.permissions?.query;
|
||||
if (originalQuery) {
|
||||
window.navigator.permissions.query = (params) => {
|
||||
if (params.name === 'notifications')
|
||||
return Promise.resolve({ state: Notification.permission });
|
||||
return originalQuery(params);
|
||||
};
|
||||
}
|
||||
`;
|
||||
|
||||
// --- Selectors (mirrored from Selectors.cs) ---
|
||||
const Selectors = {
|
||||
LiveSearchButton: 'button.livesearch-btn, button:has-text("Activate Live Search")',
|
||||
|
|
@ -152,24 +122,14 @@ function handleWebSocket(ws, searchId) {
|
|||
|
||||
async function cmdStart(reqId, params) {
|
||||
const { browserUserDataDir, headless, dashboardUrl } = params;
|
||||
log(`Starting browser, userDataDir=${browserUserDataDir}, headless=${headless}`);
|
||||
log(`Starting browser (stealth), userDataDir=${browserUserDataDir}`);
|
||||
|
||||
context = await chromium.launchPersistentContext(browserUserDataDir, {
|
||||
channel: "chrome",
|
||||
headless: !!headless,
|
||||
headless: false,
|
||||
viewport: null,
|
||||
args: [
|
||||
"--disable-blink-features=AutomationControlled",
|
||||
"--disable-features=AutomationControlled",
|
||||
"--no-first-run",
|
||||
"--no-default-browser-check",
|
||||
"--disable-infobars",
|
||||
],
|
||||
ignoreDefaultArgs: ["--enable-automation"],
|
||||
});
|
||||
|
||||
await context.addInitScript(STEALTH_SCRIPT);
|
||||
|
||||
if (dashboardUrl) {
|
||||
const pages = context.pages();
|
||||
if (pages.length > 0) {
|
||||
|
|
@ -181,7 +141,7 @@ async function cmdStart(reqId, params) {
|
|||
log(`Dashboard opened: ${dashboardUrl}`);
|
||||
}
|
||||
|
||||
log("Browser launched (stealth active)");
|
||||
log("Browser launched (playwright-extra stealth active)");
|
||||
sendResponse(reqId);
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +190,6 @@ async function cmdPauseSearch(reqId, params) {
|
|||
|
||||
async function cmdClickTravel(reqId, params) {
|
||||
const { pageId, itemId } = params;
|
||||
// pageId is a searchId or scrapId
|
||||
let page = searchPages.get(pageId) || scrapPages.get(pageId)?.page;
|
||||
if (!page) {
|
||||
sendResponse(reqId, { clicked: false });
|
||||
|
|
|
|||
24
tools/trade-daemon/package-lock.json
generated
24
tools/trade-daemon/package-lock.json
generated
|
|
@ -8,7 +8,7 @@
|
|||
"name": "trade-daemon",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"playwright": "^1.49.0"
|
||||
"patchright": "^1.57.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
|
|
@ -25,16 +25,16 @@
|
|||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright": {
|
||||
"version": "1.58.2",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.58.2.tgz",
|
||||
"integrity": "sha512-vA30H8Nvkq/cPBnNw4Q8TWz1EJyqgpuinBcHET0YVJVFldr8JDNiU9LaWAE1KqSkRYazuaBhTpB5ZzShOezQ6A==",
|
||||
"node_modules/patchright": {
|
||||
"version": "1.57.0",
|
||||
"resolved": "https://registry.npmjs.org/patchright/-/patchright-1.57.0.tgz",
|
||||
"integrity": "sha512-pxbI/D65QiFuCY3qUXKQONRhplR3rkYFhry5ieimEbzLNxu/xfOYizQRyuMgc6F5ZoZ37QNIwZz9PWEfn6aC1Q==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright-core": "1.58.2"
|
||||
"patchright-core": "1.57.0"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
"patchright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
|
|
@ -43,13 +43,13 @@
|
|||
"fsevents": "2.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright-core": {
|
||||
"version": "1.58.2",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.58.2.tgz",
|
||||
"integrity": "sha512-yZkEtftgwS8CsfYo7nm0KE8jsvm6i/PTgVtB8DL726wNf6H2IMsDuxCpJj59KDaxCtSnrWan2AeDqM7JBaultg==",
|
||||
"node_modules/patchright-core": {
|
||||
"version": "1.57.0",
|
||||
"resolved": "https://registry.npmjs.org/patchright-core/-/patchright-core-1.57.0.tgz",
|
||||
"integrity": "sha512-um/9Wue7IFAa9UDLacjNgDn62ub5GJe1b1qouvYpELIF9rsFVMNhRo/rRXYajupLwp5xKJ0sSjOV6sw8/HarBQ==",
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"playwright-core": "cli.js"
|
||||
"patchright-core": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@
|
|||
"type": "module",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"playwright": "^1.49.0"
|
||||
"patchright": "^1.57.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue