Support for "@require file://..." ?

mnucci
Posts: 3
Joined: 11.06.12 01:36:07

Re: Support for "@require file://..." ?

Post by mnucci » 11.06.12 01:44:14

I am also have great trouble getting this to work. I am on a Mac, Chrome Version 20.0.1132.27 beta using TM 2.4.2719. I am trying to require a local file.

I have tried many variations of the @require line (samples below) and every time, the script seems to stop running if this line is present. If removed, the script runs fine. I would like to put the file in the users home directory.

// @require file://Info.js
// @require file://~\Info.js
// @require file://~/Info.js

Also, what should the Info.js file look like? Do I need a header section like (below) before I put the code I want included?

// ==UserScript==
// @name My Fancy New Userscript
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match http://*/*
// @copyright 2012+, You
// ==/UserScript==

Sorry for the noob questions.

Thanks in advance, love your work!!!!

M

User avatar
derjanb
Site Admin
Posts: 2152
Joined: 20.01.06 02:16:15
Contact:

Re: Support for "@require file://..." ?

Post by derjanb » 11.06.12 16:39:26

According to this:

http://stackoverflow.com/questions/1719 ... ab-on-os-x

the URI at Mac OS X needs to be something like this:

Code: Select all

// @require file:///Users/bernd/Info.js
(in case your name is "bernd") ;)
ImageIf you like what I'm doing, please consider a donation here. Image

mnucci
Posts: 3
Joined: 11.06.12 01:36:07

Re: Support for "@require file://..." ?

Post by mnucci » 11.06.12 17:45:27

Thanks,

That worked but my challenge now is that I don't want to have to specify the UserName in the path since I won't know it. I would like to use the ~/ to go to the default user's home directory, that way my source is generic and will update without any editing from the end user.

But when I replace

// @require file:///Users/bernd/Info.js

with

// @require file:///~/Info.js

the script just stops.

Any suggestions?

M

kynikos
Posts: 16
Joined: 19.04.12 16:02:02

Re: Support for "@require file://..." ?

Post by kynikos » 12.06.12 01:13:48

I still can't make this work on TM 2.4.2724 (beta) ("Allow access to file URLs" is enabled), Chromium 19.0.1084.52 (0), Arch Linux i686.

What am I doing wrong?

Code: Select all

// ==UserScript==
// @name       Test
// @namespace  test
// @version    0.1
// @match      http://en.wikipedia.org/*
// @require    file:///home/dario/Desktop/test.js
// ==/UserScript==

alert('TEST 1');

main();
/home/dario/Desktop/test.js

Code: Select all

var main = function () {
    alert('TEST 2');
};
The console just prints "Tampermonkey started" but nothing is alerted and no errors are output.

mnucci
Posts: 3
Joined: 11.06.12 01:36:07

Re: Support for "@require file://..." ?

Post by mnucci » 12.06.12 07:39:21

@kynikos, I had that problem when I accidentally used file:///home/... rather than file:///Users/...

Give that a try and see.

Mine is working now but I still can't get my file:///~/... to work.

kynikos
Posts: 16
Joined: 19.04.12 16:02:02

Re: Support for "@require file://..." ?

Post by kynikos » 12.06.12 10:45:52

@mnucci, thanks, but the fact is that you're on a Mac and I'm on Linux :) I've tried that just for doubt's sake, and of course it doesn't work for me

About your problem, theoretically the right path should be "file://~/" (without the root slash), but I doubt that it will work, you're not in a console after all

User avatar
derjanb
Site Admin
Posts: 2152
Joined: 20.01.06 02:16:15
Contact:

Re: Support for "@require file://..." ?

Post by derjanb » 12.06.12 11:00:06

kynikos wrote:@mnucci, thanks, but the fact is that you're on a Mac and I'm on Linux :) I've tried that just for doubt's sake, and of course it doesn't work for me

About your problem, theoretically the right path should be "file://~/" (without the root slash), but I doubt that it will work, you're not in a console after all
As far as I know you have to qualifiy the whole path i.e. "/home/username/test.js".

Can you do me a favour and try this with Chromium or Google Chrome whichever is currently not installed? By doing this we can make sure that you test this at a clean and fresh setup.

https://wiki.archlinux.org/index.php/Chromium
http://cyruslab.wordpress.com/2012/02/0 ... le-chrome/

Otherwise I'll setup a ArchLinux VM and check what is going on there.
ImageIf you like what I'm doing, please consider a donation here. Image

kynikos
Posts: 16
Joined: 19.04.12 16:02:02

Re: Support for "@require file://..." ?

Post by kynikos » 12.06.12 18:44:28

I've preferred installing Ubuntu 12.04 in VirtualBox: then I've installed Chromium 18.0.1025.151 (Developer Build 130497 Linux) and Tampermonkey 2.5.16.1 (beta) (Allow access to file URLs is enabled). Unfortunately the script I've posted above doesn't work either.

T4g1
Posts: 5
Joined: 18.04.12 23:38:12

Re: Support for "@require file://..." ?

Post by T4g1 » 12.06.12 19:38:48

Does file://... also work for an @ressource line ?

Like in:

Code: Select all

// @resource    truccss file://C:\truc.css 

(...)

myCss = GM_getResourceText("truccss")

User avatar
derjanb
Site Admin
Posts: 2152
Joined: 20.01.06 02:16:15
Contact:

Re: Support for "@require file://..." ?

Post by derjanb » 13.06.12 12:55:15

Does file://... also work for an @ressource line ?
Not yet, but will be part of next beta version.
kynikos wrote:I've preferred installing Ubuntu 12.04 in VirtualBox: then I've installed Chromium 18.0.1025.151 (Developer Build 130497 Linux) and Tampermonkey 2.5.16.1 (beta) (Allow access to file URLs is enabled). Unfortunately the script I've posted above doesn't work either.
I really don't know what's going on at you...

I've tested this with a clean installation @ Ubuntu 12.04 with:

Google Chrome Version 20.0.1132.27 beta
Chromium 18.0.1025.168 (Developer Build 134367 Linux) Ubuntu 12.04

I used the script from above and only changed the home folder:

Code: Select all

// ==UserScript==
// @name       Test
// @namespace  test
// @version    0.1
// @match      http://en.wikipedia.org/*
// @require    file:///home/janb/Desktop/test.js
// ==/UserScript==

alert('TEST 1');

main();
/home/janb/Desktop/test.js

Code: Select all

var main = function () {
    alert('TEST 2');
};
Can you please attach the background console output (tampermonkey.net/faq -> Q600) after settings the LogLevel to "trace" at the TM settings tab.

Thanks.
ImageIf you like what I'm doing, please consider a donation here. Image

kynikos
Posts: 16
Joined: 19.04.12 16:02:02

Re: Support for "@require file://..." ?

Post by kynikos » 14.06.12 22:39:21

Thank you derjanb for your patience :P

Today the situation has changed a little bit (beta version is now 2.5.17), now I get the 'TEST 1' alert, but not the other one, in fact the console prints "ReferenceError: main is not defined".

After many refreshes of Wikipedia's Main Page (where the test script is set to work) I've seen that I get two kinds of output in the console (with apparently random frequency), not even talking about the fact that sometimes (still apparently random, but more rarely) I even get the 'TEST 2' alert.

This behaviour is so weird that I have no clue on how to reproduce any of those different results.

I admit I haven't been able to understand how to properly copy the output from Chromium's console, this is what I've managed to do:

Output 1

Code: Select all

loadListener http://en.wikipedia.org/wiki/Main_Page loading
background.js:797bg: setBadge: 1
background.js:561back: request.method prepare id 4652210620
background.js:865bg: reset AllURL[2]
background.js:539storage refresh/remove listeners of tab 2
background.js:289TM_storage.listValues
background.js:517determineScriptsToRun @http://en.wikipedia.org/wiki/Main_Page
background.js:277TM_storage.getValue
background.js:506bg: @match 'http://en.wikipedia.org/*' matched (Test)
background.js:277TM_storage.getValue
background.js:277TM_storage.getValue
background.js:277TM_storage.getValue
background.js:521schedule script Test
background.js:522determineScriptsToRun sort
background.js:873check Test for enabled:true
background.js:866Add to AllURL[2] -> http://en.wikipedia.org/wiki/Main_Page
background.js:797bg: setBadge: 1
background.js:80cache: missed 'file:///home/dario/Desktop/test.js'
background.js:344requires file:///home/dario/Desktop/test.js
background.js:648back: request.method prepare end!
background.js:98Unable to post message to file://. Recipient has origin chrome-extension://gcalenpjmijncebpfijmoaglllgpjagf.
bkbackground.js:98
background.js:94Resource interpreted as Document but transferred with MIME type application/javascript: "file:///home/dario/Desktop/test.js?gimmeSource=1".
b.getSourcebackground.js:94
aJ.getRequiresbackground.js:347
aJ.contentLoadbackground.js:352
aobackground.js:878
jbackground.js:628
chrome.Event.dispatchextensions/event.js:183
chromeHidden.Port.dispatchOnConnect.connectEventextensions/miscellaneous_bindings.js:130
chrome.Event.dispatchextensions/event.js:183
chromeHidden.Port.dispatchOnMessageextensions/miscellaneous_bindings.js:177
background.js:814xmlhttprequest
background.js:816bg: process request to http://en.wikipedia.org/w/index.php?title=Special%3ABannerListLoader&cache=/cn.js&language=en&project=wikipedia&country=IT
background.js:817[
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
]
background.js:823[
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
]
background.js:858loadListener http://en.wikipedia.org/wiki/Main_Page complete
background.js:351Run script Test @ http://en.wikipedia.org/wiki/Main_Page
background.js:277TM_storage.getValue
background.js:551storage add listener Test 4652210620
background.js:797bg: setBadge: 1
background.js:277TM_storage.getValue
Output 2

Code: Select all

background.js:858loadListener http://en.wikipedia.org/wiki/Main_Page loading
background.js:797bg: setBadge: 1
background.js:561back: request.method prepare id 5582902612
background.js:865bg: reset AllURL[2]
background.js:539storage refresh/remove listeners of tab 2
background.js:289TM_storage.listValues
background.js:517determineScriptsToRun @http://en.wikipedia.org/wiki/Main_Page
background.js:277TM_storage.getValue
background.js:506bg: @match 'http://en.wikipedia.org/*' matched (Test)
background.js:277TM_storage.getValue
background.js:277TM_storage.getValue
background.js:277TM_storage.getValue
background.js:521schedule script Test
background.js:522determineScriptsToRun sort
background.js:873check Test for enabled:true
background.js:866Add to AllURL[2] -> http://en.wikipedia.org/wiki/Main_Page
background.js:797bg: setBadge: 1
background.js:80cache: missed 'file:///home/dario/Desktop/test.js'
background.js:344requires file:///home/dario/Desktop/test.js
background.js:648back: request.method prepare end!
background.js:94Resource interpreted as Document but transferred with MIME type application/javascript: "file:///home/dario/Desktop/test.js?gimmeSource=1".
background.js:814xmlhttprequest
background.js:816bg: process request to http://en.wikipedia.org/w/index.php?title=Special%3ABannerListLoader&cache=/cn.js&language=en&project=wikipedia&country=IT
background.js:817[
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
]
background.js:823[
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
]
background.js:858loadListener http://en.wikipedia.org/wiki/Main_Page complete
background.js:351Run script Test @ http://en.wikipedia.org/wiki/Main_Page
background.js:277TM_storage.getValue
background.js:551storage add listener Test 5582902612
background.js:797bg: setBadge: 1
background.js:81cache: check
Maybe it's a problem with the cache? :roll:

(Just in case you were wondering:

Code: Select all

$ cat /home/dario/Desktop/test.js 
var main = function () {
    alert('TEST 2');
};
$
So the file _is_ there)

User avatar
derjanb
Site Admin
Posts: 2152
Joined: 20.01.06 02:16:15
Contact:

Re: Support for "@require file://..." ?

Post by derjanb » 16.06.12 11:03:58

Code: Select all

background.js:80cache: missed 'file:///home/dario/Desktop/test.js'
background.js:344requires file:///home/dario/Desktop/test.js
background.js:648back: request.method prepare end!
background.js:98Unable to post message to file://. Recipient has origin chrome-extension://gcalenpjmijncebpfijmoaglllgpjagf.
bkbackground.js:98
background.js:94Resource interpreted as Document but transferred with MIME type application/javascript: "file:///home/dario/Desktop/test.js?gimmeSource=1".
b.getSourcebackground.js:94
aJ.getRequiresbackground.js:347
aJ.contentLoad
This is the problem... Hmm, I have do to some more reseach. Thanks for debug output.
ImageIf you like what I'm doing, please consider a donation here. Image

kynikos
Posts: 16
Joined: 19.04.12 16:02:02

Re: Support for "@require file://..." ?

Post by kynikos » 16.06.12 23:18:00

Well it seems it was indeed a problem with the cache, tonight I've cleared it once again, and this time it's worked, I can use the file protocol!!! :D
I'm sorry for the noise, however I'm sure I had cleared the cache even more than once, and it's strange that it was the problem, since it was a clean Ubuntu installation after all... Is it normal that after installing/editing/updating TM scripts one has to clear the cache to make the new version work?
Well, in any case thank you again for your help, now I can debug my application much more easily without having to upload every update to the server!

User avatar
derjanb
Site Admin
Posts: 2152
Joined: 20.01.06 02:16:15
Contact:

Re: Support for "@require file://..." ?

Post by derjanb » 18.06.12 14:57:35

kynikos wrote:Is it normal that after installing/editing/updating TM scripts one has to clear the cache to make the new version work?
No, this isn't normal. The only thing I've seen so far is that sometimes when TM is updated a Chrome restart is necessary to make TM working right again...

Ok, so have fun with your file URIs and just report back if there will be issues again. ;)
ImageIf you like what I'm doing, please consider a donation here. Image

Post Reply

Return to “Solved, Answered or Outdated”

Who is online

Users browsing this forum: No registered users and 0 guests