gildas-lormeau / single-file-cli

CLI tool for saving a faithful copy of a complete web page in a single HTML file (based on SingleFile)
GNU Affero General Public License v3.0
540 stars 58 forks source link

Running singlefile-cli with a chrome extension #16

Open klemenStanic opened 1 year ago

klemenStanic commented 1 year ago

How do I run a chrome extension (e.g. IDontCareAboutCookies) within the webdriver? I tried running the single-file cli with

./single-file --browser-executable-path="/opt/google/chrome/google-chrome" --browser-args='["--no-sandbox", "--load-extension=./3.4.6_0.crx"]' https://www.bbc.com --dump-content

but the extension doesn't seem to work, and the returned single-file contains the popups. The path to the extension is correct. Any ideas?

sdht0 commented 1 year ago

Extensions cannot be run in headless mode, which single-file-cli uses by default.

Here's what I use:

home_config="/home/<user>/.config"
ublock_path="$home_config/chromium/Default/Extensions/cjpalhdlnbpafiamejdnhcphjbkeiagm/1.44.2_1"
singlefile_opts=(
    --browser-headless false
    --browser-args '["--user-data-dir='$home_config'/chromium/Default","--disable-extensions-except='$ublock_path'","--load-extension='$ublock_path'"]'
)
single-file-cli "${singlefile_opts[@]}" <url>

In addition, I also had to do this once:

Adapt to your extensions accordingly. If you also use chrome/chromium as your main browser, use a separate profile for single-file-cli by creating one and changing the paths above.