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

Allow scripts to execute on the file: protocol #2780

Merged
merged 2 commits into from Jan 9, 2018

Conversation

Sxderp
Copy link
Contributor

@Sxderp Sxderp commented Dec 27, 2017

@arantius arantius added this to the 4.2 milestone Dec 27, 2017
@Sxderp Sxderp force-pushed the execute-user-scripts-on-file branch from 0aa57c6 to e6bcbe1 Compare December 29, 2017 19:35
@Sxderp
Copy link
Contributor Author

Sxderp commented Dec 29, 2017

In #2782 I mentioned that I didn't recall how I stumbled upon the error. Well, I figured it out. It was when I was working on this pull request. I found that out as I was going over the tests that I had git stash (and subsequently forgot about).

I've rebased this pull on to #2782. As well as pushed the tests.

@arantius
Copy link
Collaborator

arantius commented Jan 5, 2018

I checked out this branch and installed this script:

// ==UserScript==
// @name     Run-on-file
// @version  1
// @grant    none
// @include  file:///*
// ==/UserScript==

console.log('GM script running on file!');

But I don't see the log message. This switches to webNavigation.onCommitted to detect execution time, which AFAICT does not fire for files (because they're not "web" navigations?).

@arantius arantius modified the milestones: 4.2, 4.x Jan 5, 2018
@Sxderp
Copy link
Contributor Author

Sxderp commented Jan 5, 2018

But I don't see the log message.

Interesting. At the moment I don't have access to newer versions of FF to test, but it worked on RHEL6 FF 52.5.1. And if I'm remembering correctly it should have worked on elementaryOS (Ubuntu based) FF 57.? (although it may have been on nightly and therefore FF 59.?).

I don't recall testing on my Windows.

@arantius
Copy link
Collaborator

arantius commented Jan 5, 2018

I'm testing on Ubuntu, FF 59.

@erosman
Copy link

erosman commented Jan 6, 2018

But I don't see the log message. This switches to webNavigation.onCommitted to detect execution time, which AFAICT does not fire for files (because they're not "web" navigations?).

I have an addon where I use webRequest which also doesn't fire on local locations i.e. about: view-source: moz-extension: chrome: resource: file:
I guess they used the same approach for webNavigation

I overcame the problem by adding tabs.onUpdated listener.

Note: tabs.onUpdated fires too many times.
You would need to check for changeInfo.url and then use tabInfo.url and then avoid reinjecting the same script again.

However ............... It says here as well the API doesn't allow injection to file at all (unless manually allowed by the user) :(

https://stackoverflow.com/questions/33575973/how-to-get-content-scripts-to-execute-in-file-urls-in-a-chrome-extension

https://stackoverflow.com/questions/34250957/google-chrome-chromium-event-filter-local-file-hostname

@Sxderp
Copy link
Contributor Author

Sxderp commented Jan 6, 2018

I'm testing on Ubuntu, FF 59.

Weird. I just double checked on elementaryOS FF 57 + 59, both worked. Also tested on Windows 59, worked as well.

I could start up a Ubuntu VM and see if it's just that platform (which is again, weird).


I tested by typing the path into the URL and by running firefox ./test.html. I was unable to test drag + drop on the elementaryOS (RIP, can't seem to drag files using whatever the standard manager is). But drag + drop worked on Windows.

@Sxderp Sxderp force-pushed the execute-user-scripts-on-file branch from e6bcbe1 to cef4720 Compare January 6, 2018 16:28
@Sxderp
Copy link
Contributor Author

Sxderp commented Jan 6, 2018

Oh, I just rebased this and #2782 on master. So if you test, then make sure you account for #2652

@erosman
Copy link

erosman commented Jan 7, 2018

Is there a beta to test?

@Sxderp Sxderp force-pushed the execute-user-scripts-on-file branch from cef4720 to 3a01c63 Compare January 8, 2018 16:20
@Sxderp
Copy link
Contributor Author

Sxderp commented Jan 8, 2018

Is there a beta to test?

Nothing has been pushed to AMO. You can always check out my branch and manually install from file or load temporary add-on.

@Sxderp
Copy link
Contributor Author

Sxderp commented Jan 8, 2018

I grabbed an Ubuntu VM (nothing to install an actual copy on at the moment) and see no problems. After I enabled GM (since it's currently off by default), I performed the same tests as above, drag+drop, URI navigation, and firefox index.html. With all three I saw the logged message in the page console.

@Sxderp Sxderp force-pushed the execute-user-scripts-on-file branch from 3a01c63 to 43d7cfb Compare January 8, 2018 19:36
@arantius arantius modified the milestones: 4.x, 4.2 Jan 9, 2018
@arantius
Copy link
Collaborator

arantius commented Jan 9, 2018

Tried to test again and I agree that it works. Wonder what I did wrong before.

@arantius arantius merged commit 43d7cfb into greasemonkey:master Jan 9, 2018
@Sxderp Sxderp deleted the execute-user-scripts-on-file branch January 11, 2018 00:22
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

Successfully merging this pull request may close these issues.

None yet

3 participants