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
539 stars 57 forks source link

Executing the extension from console? #60

Closed You-Honey closed 3 months ago

You-Honey commented 8 months ago

Describe the bug When using the extension and saving a website everything works perfect.

When I inject the lib/single-file.js to the webpage and run either:

const { content, title, filename } = await singlefile.getPageData({
  removeHiddenElements: true,
  removeUnusedStyles: true,
  removeUnusedFonts: true,
  removeImports: true,
  blockScripts: true,
  blockAudios: true,
  blockVideos: true,
  compressHTML: true,
  removeAlternativeFonts: true,
  removeAlternativeMedias: true,
  removeAlternativeImages: true,
  groupDuplicateImages: true
});

Or

const { content, title, filename } = await singlefile.getPageData({
    removeHiddenElements: false,
    removeUnusedStyles: false,
    removeUnusedFonts: false,
    removeImports: false,
    blockScripts: false,
    blockAudios: false,
    blockVideos: false,
    compressHTML: false,
    removeAlternativeFonts: false,
    removeAlternativeMedias: false,
    removeAlternativeImages: false,
    groupDuplicateImages: false
  });

Everything works almost perfectly but the website's responsiveness changes.

Additional context I did the test with my own browser but the use case will be run inside Playwright.

So the question is, if I install the extension to my Playwrights' browser, can I run the extension programmatically somehow?

I could simulate they hotkey to run it but I have no idea how to handle the download prompt.

Is there a way to run the extension from the console?

Cheers!

gildas-lormeau commented 8 months ago

You can use SingleFile CLI, there is an implementation for playwright, see https://github.com/gildas-lormeau/single-file-cli/blob/master/back-ends/playwright-chromium.js.

You-Honey commented 8 months ago

This is interesting, thank you!