DmitryBaranovskiy / raphael

JavaScript Vector Library
https://dmitrybaranovskiy.github.io/raphael/
MIT License
11.26k stars 1.67k forks source link

Raphael with Greasemonkey gives undefined #615

Open cletusc opened 12 years ago

cletusc commented 12 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

Many thanks my friend :)