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

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

Open
sdht0 opened this issue Aug 26, 2022 · 6 comments
Open

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

sdht0 opened this issue Aug 26, 2022 · 6 comments

Comments

@sdht0
Copy link

sdht0 commented Aug 26, 2022

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
Copy link
Author

sdht0 commented Aug 26, 2022

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

@sdht0
Copy link
Author

sdht0 commented Aug 26, 2022

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
Copy link
Owner

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
Copy link
Author

sdht0 commented Aug 30, 2022

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
Copy link
Owner

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
Copy link
Author

sdht0 commented Sep 1, 2022

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.

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

No branches or pull requests

2 participants