Class: Html2rss::RequestService::BrowserlessStrategy
- Defined in:
- lib/html2rss/request_service/browserless_strategy.rb
Overview
Browserless.io strategy to request websites.
Provide the WebSocket URL and your API token via environment variables:
- BROWSERLESS_IO_WEBSOCKET_URL
- BROWSERLESS_IO_API_TOKEN
To use this strategy, you need to have a Browserless.io account or run a local Browserless.io instance.
To run a local Browserless.io instance, you can use the following Docker command:
docker run \
--rm \
-p 3000:3000 \
-e "CONCURRENT=10" \
-e "TOKEN=6R0W53R135510" \
ghcr.io/browserless/chromium
When running locally, you can skip setting the environment variables, as above commands are aligned with the default values.
Instance Method Summary collapse
-
#browser_ws_endpoint ⇒ String
The Browserless websocket endpoint with token query param.
-
#execute ⇒ Response
Executes a Browserless-backed request with the shared request policy.
Methods inherited from Strategy
Constructor Details
This class inherits a constructor from Html2rss::RequestService::Strategy
Instance Method Details
#browser_ws_endpoint ⇒ String
Returns the Browserless websocket endpoint with token query param.
49 50 51 52 53 54 55 56 |
# File 'lib/html2rss/request_service/browserless_strategy.rb', line 49 def browser_ws_endpoint @browser_ws_endpoint ||= begin ws_url = ENV.fetch('BROWSERLESS_IO_WEBSOCKET_URL', 'ws://127.0.0.1:3000') api_token = browserless_api_token(ws_url) "#{ws_url}?token=#{api_token}" end end |
#execute ⇒ Response
Executes a Browserless-backed request with the shared request policy.
39 40 41 42 43 44 |
# File 'lib/html2rss/request_service/browserless_strategy.rb', line 39 def execute validate_request! execute_browserless_request rescue Puppeteer::TimeoutError => error raise RequestTimedOut, error. end |