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

Inserting scripts using browser-script does not seem to be working #8

Open sdht0 opened 1 year ago

sdht0 commented 1 year ago

Hi,

Running single-file --browser-script "./script.js" "<url>" simply exits seemingly without any output or error but removing the --browser-script argument makes it work as expected.

script.js contains the second script from https://github.com/gildas-lormeau/SingleFile/wiki/How-to-execute-a-user-script-before-a-page-is-saved.

How do I get it to work?

Thanks.

sdht0 commented 1 year ago

I should perhaps mention I use chromium using --browser-executable-path $(which chromium).

sdht0 commented 1 year ago

Okay it seems to be due to the type of browser-script being array in args.js. Changing it to string makes it work for me! Not sure how to correctly pass the arguments for array type. Using -- as per yargs doc does not seem to work.

gildas-lormeau commented 1 year ago

I agree that the help is not very clear about this. Actually, you can pass --browser-script multiple times, that's why it appears as an array.

sdht0 commented 1 year ago

So are you able to use the cli with only one argument to --browser-script. What I show in my first post is that the command does nothing when I only have one script.

gildas-lormeau commented 1 year ago

Sorry for the misunderstanding, I guess I was tired when I replied.

I confirm that running single-file --browser-script test.js https://www.example.com works for me. The test.js file contains onload = () => document.body.innerHTML += "Hello world!"; and the saved page contains "Hello world!" as expected.

sdht0 commented 1 year ago

single-file --browser-script test.js --browser-executable-path $(which chromium) https://www.example.com works single-file --browser-executable-path $(which chromium) --browser-script test.js https://www.example.com does not

So --browser-script cannot be the last argument if there are multiple arguments being passed. Seems like a yargs bug.