Class: Ask::WebFetch::Backends::AttachedBrowser
- Inherits:
-
Object
- Object
- Ask::WebFetch::Backends::AttachedBrowser
- Defined in:
- lib/ask/web_fetch/backends/attached_browser.rb
Overview
Drives an already-running Chrome — one started with
--remote-debugging-port=9222 — over the Chrome DevTools Protocol,
reusing Ferrum's battle-tested CDP WebSocket client.
This is the mode the Browser backend uses when ASK_WEB_FETCH_CDP_URL is set (e.g. http://127.0.0.1:9222). It is the trusted context a freshly launched automation browser can never be: a long-lived Chrome with a mature profile and any cookies (like cf_clearance) it has already earned, so sites whose invisible challenges soft-block fresh profiles load normally here.
Each page is its own CDP target, created and closed by us — existing tabs are never touched.
Defined Under Namespace
Classes: Page
Instance Method Summary collapse
-
#create_page ⇒ Object
Creates a page as a fresh tab in the attached browser.
-
#initialize(ws_url, timeout:, client: nil) ⇒ AttachedBrowser
constructor
A new instance of AttachedBrowser.
Constructor Details
#initialize(ws_url, timeout:, client: nil) ⇒ AttachedBrowser
Returns a new instance of AttachedBrowser.
22 23 24 25 26 |
# File 'lib/ask/web_fetch/backends/attached_browser.rb', line 22 def initialize(ws_url, timeout:, client: nil) @ws_url = ws_url @timeout = timeout @client = client end |
Instance Method Details
#create_page ⇒ Object
Creates a page as a fresh tab in the attached browser.
29 30 31 32 33 34 35 |
# File 'lib/ask/web_fetch/backends/attached_browser.rb', line 29 def create_page # Capture the frontmost app once per browser instance, not per # page: a batch of fetches steals focus once and restores to the # same app, and consecutive fetches don't fight each other. @frontmost_app ||= FocusRestorer.capture_frontmost Page.new(client, timeout: @timeout, restore_focus_to: @frontmost_app) end |