Class: Html2rss::RequestService::BrowserlessStrategy

Inherits:
Strategy
  • Object
show all
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:

“‘sh 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

Methods inherited from Strategy

#initialize

Constructor Details

This class inherits a constructor from Html2rss::RequestService::Strategy

Instance Method Details

#browser_ws_endpointObject



43
44
45
46
47
48
49
50
# File 'lib/html2rss/request_service/browserless_strategy.rb', line 43

def browser_ws_endpoint
  @browser_ws_endpoint ||= begin
    api_token = ENV.fetch('BROWSERLESS_IO_API_TOKEN', '6R0W53R135510')
    ws_url = ENV.fetch('BROWSERLESS_IO_WEBSOCKET_URL', 'ws://127.0.0.1:3000')

    "#{ws_url}?token=#{api_token}"
  end
end

#executeObject

return [Response]



35
36
37
38
39
40
41
# File 'lib/html2rss/request_service/browserless_strategy.rb', line 35

def execute
  Puppeteer.connect(browser_ws_endpoint:) do |browser|
    PuppetCommander.new(ctx, browser).call
  ensure
    browser.disconnect
  end
end