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

User scripts for local files ("file:///" protocol) #2693

Closed
FeBe95 opened this Issue Nov 17, 2017 · 17 comments

Comments

Projects
None yet
5 participants
@FeBe95

FeBe95 commented Nov 17, 2017

I know it is stated in the Greasemonkey (4) wiki that "User scripts will not run on documents from any other scheme (ftp, file, etc.) or any other part of about. ", but why is this the case? WebExtensions are able to access local files and Violentmonkey for example is able to execute user scripts on "file:///" pages.

@StigNygaard

This comment has been minimized.

StigNygaard commented Nov 17, 2017

@FeBe95

This comment has been minimized.

FeBe95 commented Nov 17, 2017

The issue you linked is about installing a local myscript.user.js file, whereas my issue is about executing user scripts on pages that are local files.
For example a script that redirects local php files "file:://C:/xampp/....../index.php" to http://localhost/....../index.php.

@Sxderp

This comment has been minimized.

Contributor

Sxderp commented Nov 17, 2017

I'm actually not sure about this. Executing a user script on a file:// protocol shouldn't have any technical limitations.

@arantius

This comment has been minimized.

Collaborator

arantius commented Nov 17, 2017

Executing a user script on a file:// protocol shouldn't have any technical limitations.

Conceptually, no. Today we tabs.executeScript(), which is just a content script, which is limited. Mozilla really rushed their WebExtension decision.

I hope #2549 will help with this, but we have to wait for Firefox to unblock us there.

@FeBe95

This comment has been minimized.

FeBe95 commented Nov 17, 2017

Okay, but without Firefox changing something, Violentmonkey already is able to execute scripts on local pages. Are they doing something fundamentally different ?

@Sxderp

This comment has been minimized.

Contributor

Sxderp commented Nov 17, 2017

Conceptually, no. Today we tabs.executeScript(), which is just a content script, which is limited. Mozilla really rushed their WebExtension decision.

Content scripts will run on file:// There's just some edge case functionality in regard to certain background listeners matching on them. And of course the async request for them which spawned that particular issue[1]. In fact webNavigation.onCommitted matches file:// protocol just fine.

In the current codebase the only thing preventing scripts from running on file:// is here.

[1] @erosman made some good points in regard to local file install workflow. I think it should be considered.

@arantius arantius added this to the 4.x milestone Nov 21, 2017

@erosman

This comment has been minimized.

erosman commented Dec 27, 2017

In the current codebase the only thing preventing scripts from running on file:// is here.

Is there an update to this?

@Sxderp

This comment has been minimized.

Contributor

Sxderp commented Dec 27, 2017

Is there an update to this?

Hasn't changed. Should be a quick fix to execute user scripts on file://. Of course, installing still has the same issues as discussed in the other issue.

I'll post back in a few minutes.

@erosman

This comment has been minimized.

erosman commented Dec 27, 2017

@Sxderp Thanks
I have been waiting for this for a while as I run some tools on a local file:// which runs into trouble (especially with CORS) if run as a normal page script.
I was about write an addon for myself just for that, if this issue wasn't fixed. ;)

Is there an ETA for the release?

@Sxderp

This comment has been minimized.

Contributor

Sxderp commented Dec 27, 2017

Is there an ETA for the release?

Not that I have any control over. It's when @arantius has the time.

@arantius arantius modified the milestones: 4.x, 4.2 Dec 27, 2017

@erosman

This comment has been minimized.

erosman commented Jan 4, 2018

@arantius Do you have a release date for 4.2?

@erosman

This comment has been minimized.

erosman commented Jan 10, 2018

GM 4.2beat2
When running GM on local file file:///C:/****** I am getting an error.

Code:

Line 57: console.log(typeof GM.xmlHttpRequest);

Line 191: console.log(typeof GM.xmlHttpRequest);
Line 192:  GM.xmlHttpRequest({

Result:

function  Tester:417
function  Tester:551
ReferenceError: GM is not defined  Tester.js:190:3

Line 190 is not part of Tester.js

@arantius

This comment has been minimized.

Collaborator

arantius commented Jan 10, 2018

In what way is this comment related to this issue?

@erosman

This comment has been minimized.

erosman commented Jan 10, 2018

In what way is this comment related to this issue?

I thought it was obvious since the subject is ("file:///" protocol) but I updated the above post for clarification.

@Sxderp

This comment has been minimized.

Contributor

Sxderp commented Jan 10, 2018

Can't reproduce on a Linux box, could you give us a bare working example?

My test script.

// ==UserScript==
// @name     Test File xml
// @version  1
// @grant    GM.xmlHttpRequest
// @match    file:///*
// ==/UserScript==
function results(xml) {
  console.log(xml);
}
console.log(GM);
GM.xmlHttpRequest({'url': 'https://ncgamers.org', 'onload': results});

Console

Object { info: Object, xmlHttpRequest: GM_xmlHttpRequest(d) }  Test%20File%20xml:281:1
Object { context: null, finalUrl: "https://ncgamers.org/", lengthComputable: null, loaded: null, readyState: 4, response: "<!DOCTYPE html PUBLIC "-//W3C//DTD …", responseHeaders: "Date: Wed, 10 Jan 2018 16:11:45 GMT…", responseText: "<!DOCTYPE html PUBLIC "-//W3C//DTD …", responseXML: null, status: 200, 2 more… }  Test%20File%20xml:279:3
@erosman

This comment has been minimized.

erosman commented Jan 10, 2018

Can't reproduce on a Linux box, could you give us a bare working example?

Oops.... apologies .. that was my mistake. I found out the problem (which was with an embedded script version of GM script that I was working on, not GM injected script).

Please disregard my post. It seems to be working just fine.

@Sxderp

This comment has been minimized.

Contributor

Sxderp commented Jan 14, 2018

I believe this can be closed now.

@arantius arantius modified the milestones: 4.x, 4.2 Jan 15, 2018

@arantius arantius closed this Jan 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment