simonradier / node-red-contrib-simple-webdriver

SimpleWebdriver nodes for Node-RED initially based on node-red-contrib-selenium-wd2
Apache License 2.0
14 stars 7 forks source link

Compatibility with browserless-chrome? #28

Closed FabioEight closed 1 year ago

FabioEight commented 1 year ago

Hello Simon,

First of all thanks for your work! I found the addon browserless-chrome from @alexbelgium repo: https://github.com/alexbelgium/hassio-addons/tree/master/browserless_chrome As far as I understood, this addon should start a webdriver server, basically in a container in HAOS. This is really interesting as a secondary/external webdriver would be no longer required.

I tried to start a new webdriver session following the quick start steps (https://hub.docker.com/r/browserless/chrome/#webdriver) with the following code:

const webdriver = require('selenium-webdriver');
const fs = require('fs');

const chromeCapabilities = webdriver.Capabilities.chrome();
chromeCapabilities.set(
  'chromeOptions', {
    args: [
      '--headless',
      '--no-sandbox',
      '--whitelisted-ips=""' 
    ],
  }
);

const driver = new webdriver.Builder()
  .forBrowser('chrome')
  .withCapabilities(chromeCapabilities)
  .usingServer('http://192.168.1.30:3000/webdriver') // <-- my local HAOS IP
  .build();

But the NodeRed open browser node does not open any session: image

28 Dec 16:42:29 - [info] [open browser:Apri Silentron] http://192.168.1.30:3000/ is reacheable by Node-red
[TRACE][2022-12-28T15:42:30.510Z][Object.call|api.js:34] Calling : POST http://192.168.1.30:3000/session
28 Dec 16:42:30 - [error] [open browser:Apri Silentron] Can't open an instance of chrome
28 Dec 16:42:30 - [error] [open browser:Apri Silentron] Error: HTTPError : Incorrect HTTP header 'content-type', expected 'application/json'

Do you think it's possible to run this flow all in one host sine browserless-chrome provides the webdriver? Otherwise, another way to do so might be to install Portainer (same repo) and add chromedriver, but this way seem cleaner..

PS: I noticed that if I wrongly the webdriver address (ex. forgetting the http), makes Node-Red crashing:

28 Dec 16:37:24 - [error] TypeError: Invalid URL
    at new NodeError (node:internal/errors:393:5)
    at URL.onParseError (node:internal/url:565:9)
    at new URL (node:internal/url:645:5)
    at new WebDriver (/config/node-red/node_modules/@critik/simple-webdriver/dist/webdriver.js:102:27)
    at NodeOpenBrowserConstructor._inputCallback (/config/node-red/node_modules/node-red-contrib-simple-webdriver/dist/nodes/open-browser.js:41:24)
    at /opt/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26
    at Object.trigger (/opt/node_modules/@node-red/util/lib/hooks.js:166:13)
    at NodeOpenBrowserConstructor.Node._emitInput (/opt/node_modules/@node-red/runtime/lib/nodes/Node.js:202:11)
    at NodeOpenBrowserConstructor.Node.emit (/opt/node_modules/@node-red/runtime/lib/nodes/Node.js:186:25)
    at NodeOpenBrowserConstructor.Node.receive (/opt/node_modules/@node-red/runtime/lib/nodes/Node.js:485:10)
    at Immediate.<anonymous> (/opt/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52)
    at processImmediate (node:internal/timers:471:21)
[16:37:24] INFO: Service Node-RED exited with code 1 (by signal 0)
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service nginx: stopping
[16:37:24] INFO: Service NGINX exited with code 0 (by signal 0)
s6-rc: info: service nginx successfully stopped
s6-rc: info: service init-nginx: stopping
s6-rc: info: service nodered: stopping
s6-rc: info: service init-nginx successfully stopped
[16:37:24] INFO: Service Node-RED exited with code 256 (by signal 15)
s6-rc: info: service nodered successfully stopped
s6-rc: info: service init-nodered: stopping
s6-rc: info: service init-nodered successfully stopped
s6-rc: info: service init-customizations: stopping
s6-rc: info: service init-customizations successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service base-addon-log-level: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service base-addon-log-level successfully stopped
s6-rc: info: service base-addon-banner: stopping
s6-rc: info: service base-addon-banner successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped
simonradier commented 1 year ago

Hi @FabioEight,

At least, the url you are giving is wrong :

I did some test with Browserless/chrome. Can you tell me which platform you are using for your docker? (Linux/MacOs/Windows). If it is MacOs, there is an issue in Browserless with the webdriver on ARM platform, in the other case I would like to have the docker logs as well.

Best regards,

simonradier commented 1 year ago

For the last part about the crash, I'm not able to replicate it. Could you give me your version of node-red-contrib-simple-webdriver.

Thanks,

FabioEight commented 1 year ago

Hi @FabioEight,

At least, the url you are giving is wrong :

  • You should provide the following url : http://192.168.1.30:3000/webdriver/ (the same you would provide to a selenium client)

I did some test with Browserless/chrome. Can you tell me which platform you are using for your docker? (Linux/MacOs/Windows). If it is MacOs, there is an issue in Browserless with the webdriver on ARM platform, in the other case I would like to have the docker logs as well.

Best regards,

I didn't know about the ending webdriver/ as my current config works without any subpath! I'm testing the flow and seems to be working!

For the last part about the crash, I'm not able to replicate it. Could you give me your version of node-red-contrib-simple-webdriver.

Thanks,

About this, I'm using the latest version. I'll test more and try to replicate!

Thank you!

simonradier commented 1 year ago

If you can give me a node flow which generate the error it would be great.

Best regards,