Open dev2xl opened 2 months ago
The test code
import HeroCore from '@ulixee/hero-core';
import { TransportBridge } from '@ulixee/net';
import { ConnectionToHeroCore } from '@ulixee/hero';
const bridge = new TransportBridge();
const connectionToCore = new ConnectionToHeroCore(bridge.transportToCore);
const heroCore = new HeroCore();
heroCore.addConnection(bridge.transportToClient);
import Hero from "@ulixee/hero";
(async () => {
console.log('::: START :::')
try {
const hero = new Hero({
connectionToCore,
noChromeSandbox: true,
sessionKeepAlive: true,
//userAgent: "~ chrome = 128"
});
console.log(hero.version)
await hero.goto("some url");
await hero.waitForPaintingStable();
//console.log(await hero.url);
const input = hero.querySelector('input[placeholder="test"]');
console.log('input found', !!input);
const button = hero.querySelector('button');
console.log('button found', !!button);
await hero.click(input)
console.log('input clicked')
await hero.type('test')
console.log('text typed')
}
catch (err) {
console.error(err);
}
})();
The package.json
{
"name": "test",
"version": "1.0.0",
"scripts": {
"dev": "ts-node src/index.ts",
"start": "ts-node dist/index.js",
"build": "tsc -p .",
},
"license": "MIT",
"devDependencies": {
"@types/node": "^22.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
},
"dependencies": {
"@ulixee/chrome-128-0": "^6613.114.11",
"@ulixee/hero": "2.0.0-alpha.29",
"@ulixee/hero-core": "2.0.0-alpha.29",
"@ulixee/hero-playground": "^2.0.0-alpha.29",
"@ulixee/cloud": "^2.0.0-alpha.29"
}
}
The docker image
FROM --platform=linux/amd64 node:18-slim
RUN apt-get update && \
apt-get install -y wget gnupg && \
rm -rf /var/lib/apt/lists/*
RUN wget --no-verbose -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /usr/share/keyrings/google-chrome-archive-keyring.gpg \
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome-archive-keyring.gpg] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
&& apt-get -y update \
&& apt-get install --no-install-recommends -y google-chrome-stable xvfb xauth \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY src /app/src
COPY tsconfig.json /app/tsconfig.json
RUN npm run build
CMD [ "npm", "run", "dev"]
Small note, with VPN it types correctly but without it gets stuck like the error shown.
You might pull some ideas from the Dockerfile and run options in platform. I think we had to run with ipc=host to be consistent. The VPN thing is very weird
https://github.com/ulixee/platform/tree/main/cloud/tools/docker
I created a docker image, I am running the script and after finding the input and clicking on it I tried to type some text with
await hero.type('test')
and I got the following error