You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a client and a server and made a http server for the server. and I use const hero = new Hero({ userAgent: '~ chrome >= 112 && windows >= 10', name:'teste1', // I need it to be the same name showChrome: true, noChromeSandbox: true, disableIncognito:true, connectionToCore: { host: 'localhost:3000/hero' }, }); to connect to the server
and when using await hero.close(); gera um erro no servidor
ERROR [hero-core\index] UnhandledRejection { context: {}, sessionId: null, sessionName: undefined } Error: WebSocket is not open: readyState 2 (CLOSING) at sendAfterClose (D:\nodejs\navegador_scraping\node_modules\ws\lib\websocket.js:1134:17) at WebSocket.send (D:\nodejs\navegador_scraping\node_modules\ws\lib\websocket.js:461:7) at D:\nodejs\navegador_scraping\node_modules\net\lib\WsUtils.ts:14:8 at new Promise (<anonymous>) at wsSend (D:\nodejs\navegador_scraping\node_modules\net\lib\WsUtils.ts:13:9) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async WsTransportToClient.send (D:\nodejs\navegador_scraping\node_modules\net\lib\WsTransportToClient.ts:40:7) at async ConnectionToHeroClient.handleRequest (D:\nodejs\navegador_scraping\node_modules\core\connections\ConnectionToHeroClient.ts:104:7)
and when trying to use the client again the page loads with an error
`import { CorePlugin } from '@ulixee/hero-plugin-utils';
import HeroCore from '@ulixee/hero-core';
import ExecuteJsPlugin from '@ulixee/execute-js-plugin';
import { WsTransportToClient } from '@ulixee/net';
import { WebSocketServer } from 'ws';
import * as http from 'http';
const heroCore = new HeroCore();
HeroCore.use(ExecuteJsPlugin);
heroCore.on('error', (error) => {
console.error('Erro no Hero Core:', error);
});
// Attach Hero to your Http or Https Server
async function bindHeroCore(yourHttpServer) {
const wsServer = new WebSocketServer({
server: yourHttpServer,
});
wsServer.on('connection', (ws, req) => {
// OPTIONAl: it's configured to listen on a path
if (req.url && req.url.startsWith('/hero')) {
const transport = new WsTransportToClient(ws, req);
const connection = heroCore.addConnection(transport);
//console.log(connection.core)
ws.on('close', (code, reason) => {
//connection.disconnect()
console.log('WebSocket encerrado');
});
ws.on('error', (err) => {
//connection.disconnect()
console.error('Erro no WebSocket:', err);
});
}
else {
ws.close(4001, 'Rota inválida'); // Fecha a conexão se não for para /hero
}
});
console.log('Hero Core vinculado ao servidor WebSocket');
}
// Criação de um servidor HTTP simples
const httpServer = http.createServer((req, res) => {
if (req.method === 'GET' && req.url === '/') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Servidor Hero Core está rodando. Use WebSocket em /hero');
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Rota não encontrada');
}
});
// Vincula o Hero Core ao servidor e inicia
bindHeroCore(httpServer).then(() => {
const PORT = 3000;
httpServer.listen(PORT, () => {
console.log('Servidor rodando em http://localhost:'+PORT);
console.log('Use a rota WebSocket em ws://localhost:3000/hero');
});
}).catch(err => {
console.error('Erro ao vincular Hero Core:', err);
});`
The text was updated successfully, but these errors were encountered:
I created a client and a server and made a http server for the server. and I use
const hero = new Hero({ userAgent: '~ chrome >= 112 && windows >= 10', name:'teste1', // I need it to be the same name showChrome: true, noChromeSandbox: true, disableIncognito:true, connectionToCore: { host: 'localhost:3000/hero' }, });
to connect to the serverand when using
await hero.close();
gera um erro no servidorERROR [hero-core\index] UnhandledRejection { context: {}, sessionId: null, sessionName: undefined } Error: WebSocket is not open: readyState 2 (CLOSING) at sendAfterClose (D:\nodejs\navegador_scraping\node_modules\ws\lib\websocket.js:1134:17) at WebSocket.send (D:\nodejs\navegador_scraping\node_modules\ws\lib\websocket.js:461:7) at D:\nodejs\navegador_scraping\node_modules\net\lib\WsUtils.ts:14:8 at new Promise (<anonymous>) at wsSend (D:\nodejs\navegador_scraping\node_modules\net\lib\WsUtils.ts:13:9) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async WsTransportToClient.send (D:\nodejs\navegador_scraping\node_modules\net\lib\WsTransportToClient.ts:40:7) at async ConnectionToHeroClient.handleRequest (D:\nodejs\navegador_scraping\node_modules\core\connections\ConnectionToHeroClient.ts:104:7)
and when trying to use the client again the page loads with an error
HTTP/1.1 407 Proxy Authentication Required Proxy-Authenticate: Basic realm="agent"
My server code
`import { CorePlugin } from '@ulixee/hero-plugin-utils';
import HeroCore from '@ulixee/hero-core';
import ExecuteJsPlugin from '@ulixee/execute-js-plugin';
import { WsTransportToClient } from '@ulixee/net';
import { WebSocketServer } from 'ws';
import * as http from 'http';
const heroCore = new HeroCore();
HeroCore.use(ExecuteJsPlugin);
heroCore.on('error', (error) => {
console.error('Erro no Hero Core:', error);
});
heroCore.on('close', () => {
console.log('Hero Core encerrado');
});
// Attach Hero to your Http or Https Server
async function bindHeroCore(yourHttpServer) {
const wsServer = new WebSocketServer({
server: yourHttpServer,
});
wsServer.on('connection', (ws, req) => {
// OPTIONAl: it's configured to listen on a path
if (req.url && req.url.startsWith('/hero')) {
const transport = new WsTransportToClient(ws, req);
const connection = heroCore.addConnection(transport);
//console.log(connection.core)
});
console.log('Hero Core vinculado ao servidor WebSocket');
}
// Criação de um servidor HTTP simples
const httpServer = http.createServer((req, res) => {
if (req.method === 'GET' && req.url === '/') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Servidor Hero Core está rodando. Use WebSocket em /hero');
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Rota não encontrada');
}
});
// Vincula o Hero Core ao servidor e inicia
bindHeroCore(httpServer).then(() => {
const PORT = 3000;
httpServer.listen(PORT, () => {
console.log('Servidor rodando em http://localhost:'+PORT);
console.log('Use a rota WebSocket em ws://localhost:3000/hero');
});
}).catch(err => {
console.error('Erro ao vincular Hero Core:', err);
});`
The text was updated successfully, but these errors were encountered: