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

Raphael with Greasemonkey gives undefined #615

Open
cletusc opened this issue Sep 1, 2012 · 3 comments
Open

Raphael with Greasemonkey gives undefined #615

cletusc opened this issue Sep 1, 2012 · 3 comments

Comments

@cletusc
Copy link

cletusc commented Sep 1, 2012

This is in regards to this thread: http://userscripts.org/topics/115200
When trying to use Raphael with Greasemonkey, I am getting an error as though it isn't loading.

Simplified test case

// ==UserScript==
// @name        Testing Raphael
// @namespace   #Cletus
// @include     https://www.google.com/
// @version     1
// @grant       GM_log
// @require     http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael.js
// ==/UserScript==

console.log(Raphael);

/**
 * Expected: Your browser supports SVG. You are running Raphael 2.1.0
 * Actual: window.Raphael is undefined, file:///.../raphael.js, Line 3755
 * Note: @grant set to "GM_log" to force it into a sandbox, but it still won't work with @grant set to "none".
 */

Note that once Raphael is actually defined, it works as intended.

Using

Firefox v15.0
Greasemonkey v1.0
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0

Possible cause

When digging around for the possible cause of this, I found a change that DOES fix it.
raphael.js, Line 3738
Change
oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
to
oldRaphael.was ? (g.win.Raphael = R) : (g.win.Raphael = R);
or simply
g.win.Raphael = R;

This seems to fix it, but then again I don't know of the side effects. From the looks of it, that line just checks to see if Raphael exists and overwrites it, otherwise it just creates a new variable.

Is this a known issue or has anyone else had any success with Raphael and Greasemonkey?

@drupol
Copy link

drupol commented Jan 7, 2013

I also have that problem and I'm still looking for a solution.

See: http://userscripts.org/scripts/show/140556
See: http://userscripts.org/topics/115200?page=1

@Capatcha
Copy link

a Fork from raphale-min.js to
https://raw.github.com/Capatcha/raphael/master/raphael-min-2.1.0-GM.js

You can generate it similary like:
sed -e "s/window.Raphael/Raphael/g" raphel-min.js >raphael-min-2.1-GM.js

see http://userscripts.org/topics/115200

@drupol
Copy link

drupol commented Jan 11, 2013

Many thanks my friend :)

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

3 participants