Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use SingleFile API outside of extension context? #773

Open
ralphilius opened this issue Sep 9, 2021 · 5 comments
Open

How to use SingleFile API outside of extension context? #773

ralphilius opened this issue Sep 9, 2021 · 5 comments

Comments

@ralphilius
Copy link

@ralphilius ralphilius commented Sep 9, 2021

Is your feature request related to a problem? Please describe.
I'm trying to use SingleFile on my server but I can't seems to get it to work. Do you know how I could get it to work on my server? I could use puppeteer as the browser.

Describe the solution you'd like
Something simple like

 const { html } = await singlefile.getPageData(options);
@gildas-lormeau
Copy link
Owner

@gildas-lormeau gildas-lormeau commented Sep 9, 2021

You should be able to run SingleFile on your server as a CLI tool by following the documentation here: https://github.com/gildas-lormeau/SingleFile/tree/master/cli. You could also modify the existing puppeteer code used by the CLI tool here: https://github.com/gildas-lormeau/SingleFile/blob/master/cli/back-ends/puppeteer.js. Basically the /cli folder is an answer to your question.
I also described the minimum things that should be done in order to run SingleFile outside the extension context here: #769 (comment).

@ralphilius
Copy link
Author

@ralphilius ralphilius commented Sep 9, 2021

You should be able to run SingleFile on your server as a CLI tool by following the documentation here: https://github.com/gildas-lormeau/SingleFile/tree/master/cli. You could also modify the existing puppeteer code used by the CLI tool here: https://github.com/gildas-lormeau/SingleFile/blob/master/cli/back-ends/puppeteer.js. Basically the /cli folder is an answer to your question.
I also described the minimum things that should be done in order to run SingleFile outside the extension context here: #769 (comment).

Thanks for your prompt reply.

  1. I have successfully installed and run single-file as command line here: https://github.com/gildas-lormeau/SingleFile/tree/master/cli. However, I want to use it inside my code. Do you know how should I achieve it?
  2. I read through your comment #769 (comment) earlier, but not sure how it could work in server environment where we don't have window?

@gildas-lormeau
Copy link
Owner

@gildas-lormeau gildas-lormeau commented Sep 11, 2021

  1. You could fork my code (cf. the /cli folder)
  2. The code of SingleFile is run via puppeteer in Chrome so the window object does exist

@ababushkin
Copy link

@ababushkin ababushkin commented Sep 19, 2021

The answer in the linked thread did the trick, thanks @gildas-lormeau, and brilliant work.

Is there a reason why certain parts of the page can't be saved as consistently in comparison to when I'm using the extension directly?

e.g. <model-viewer> components don't get saved property when running outside an extension context, but is saved perfectly when it is.

@gildas-lormeau
Copy link
Owner

@gildas-lormeau gildas-lormeau commented Sep 19, 2021

@ababushkin The reason is that I provided the minimum thing to do to use SingleFile outside an extension context. In order to handle custom elements with a shadow root (e.g. <model-viewer>), you have also to inject dist/single-file-bootstrap.js in the page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants