This project is archived and is in readonly mode.

#149 ✓invalid
Dan Phiffer

Greasemonkey support

Reported by Dan Phiffer | June 21st, 2008 @ 10:11 PM | in 2.0 (closed)

Comments and changes to this ticket

  • Dan Phiffer

    Dan Phiffer June 21st, 2008 @ 01:32 AM

    MooTools 1.2 does not work with Greasemonkey 0.8.20080609 and Firefox 3.0. It fails in the Window's call to the Native constructor. Here is the line in question:

    object.prototype.constructor = object;
    

    The error is "object.prototype is undefined".

    I added some console logs to inspect the contents of the window object (object.prototype is assigned to window.Window in a previous line), and I get much fewer items than if I execute the same Javascript in a normal page context.

    I added this right before the line that throws the error:

    if (options.name == 'Window') {
      for (var key in window) {
        console.log(key + '[' + typeof window[key] + ']');
      }
      console.log(legacy.prototype);
    }
    

    Here is the console log from the userscript:

    navigator[object]

    getInterface[function]

    console[undefined]

    document[object]

    addEventListener[function]

    location[object]

    netscape[undefined]

    XPCSafeJSObjectWrapper[undefined]

    XPCNativeWrapper[undefined]

    Components[undefined]

    undefined

    And here it is from the same script included on a page:

    window[object]

    $uid[function]

    $exec[function]

    Browser[object]

    $each[function]

    $A[function]

    $H[function]

    Hash[function]

    $type[function]

    $try[function]

    $time[function]

    $splat[function]

    $random[function]

    $pick[function]

    $merge[function]

    $unlink[function]

    $extend[function]

    $lambda[function]

    $arguments[function]

    $empty[function]

    $defined[function]

    $clear[function]

    $chk[function]

    Native[function]

    MooTools[object]

    console[object]

    document[object]

    addEventListener[function]

    location[object]

    navigator[object]

    netscape[object]

    XPCSafeJSObjectWrapper[function]

    XPCNativeWrapper[function]

    Components[object]

    parent[object]

    top[object]

    scrollbars[object]

    name[string]

    scrollX[number]

    scrollY[number]

    scrollTo[function]

    scrollBy[function]

    getSelection[function]

    scrollByLines[function]

    scrollByPages[function]

    sizeToContent[function]

    dump[function]

    setTimeout[function]

    setInterval[function]

    clearTimeout[function]

    clearInterval[function]

    setResizable[function]

    captureEvents[function]

    releaseEvents[function]

    routeEvent[function]

    enableExternalCapture[function]

    disableExternalCapture[function]

    prompt[function]

    open[function]

    openDialog[function]

    frames[object]

    find[function]

    applicationCache[object]

    self[object]

    screen[object]

    history[object]

    content[object]

    menubar[object]

    toolbar[object]

    locationbar[object]

    personalbar[object]

    statusbar[object]

    directories[object]

    closed[boolean]

    crypto[object]

    pkcs11[object]

    controllers[object]

    opener[object]

    status[string]

    defaultStatus[string]

    innerWidth[number]

    innerHeight[number]

    outerWidth[number]

    outerHeight[number]

    screenX[number]

    screenY[number]

    pageXOffset[number]

    pageYOffset[number]

    scrollMaxX[number]

    scrollMaxY[number]

    length[number]

    fullScreen[boolean]

    alert[function]

    confirm[function]

    focus[function]

    blur[function]

    back[function]

    forward[function]

    home[function]

    stop[function]

    print[function]

    moveTo[function]

    moveBy[function]

    resizeTo[function]

    resizeBy[function]

    scroll[function]

    close[function]

    updateCommands[function]

    atob[function]

    btoa[function]

    frameElement[object]

    showModalDialog[function]

    postMessage[function]

    removeEventListener[function]

    dispatchEvent[function]

    getComputedStyle[function]

    sessionStorage[object]

    globalStorage[object]

    [xpconnect wrapped native prototype]

    I've attached the test userscript which includes the Core and Browser modules enabled.

  • Dan Phiffer

    Dan Phiffer July 5th, 2008 @ 10:11 PM

    • Tag cleared.

    It seems that the window object just doesn't have a prototype in Firefox 3 (within Greasemonkey, that is). Weird. I attached a patch that should address the issue.

  • Jan Kassens

    Jan Kassens July 17th, 2008 @ 06:17 PM

    • State changed from “new” to “invalid”

    here's a post how to include prototypejs into a greasemonkey script. the same technique should work for mootools: http://jimbojw.com/wiki/index.ph...

  • Dan Phiffer

    Dan Phiffer July 17th, 2008 @ 06:27 PM

    Embedding Mootools using that technique will cause it to conflict with other frameworks on the page. It's not an option. Did you look at my attached patch? It's a very simple fix.

  • Jan Kassens

    Jan Kassens July 17th, 2008 @ 06:34 PM

    I'm pretty sure it wont work if you dont use it in the real window scope. Does that fix work, i.e. can you do something like $('id').fade('out'); after the fix or does it just fix the warnings?

    a mootools build without the "Browser" component should work though.

  • Dan Phiffer

    Dan Phiffer July 17th, 2008 @ 06:48 PM

    Everything works in (a slightly modified version of) 1.11, even without the real window scope.

    We're currently using that in our forthcoming release of the ShiftSpace project. For the next one after that we'd like to upgrade to 1.2 without having to modify it ourselves.

    Since ShiftSpace is a platform that uses complex UI elements, we'll be enabling almost everything in our release. If it's helpful I can do a more complete set of tests -- this ticket was simply to get the basic Core stuff working.

  • WillCz

    WillCz October 4th, 2008 @ 06:10 PM

    Dan Phiffer, can you please reupload or repost here the fix code? Your attached file doesen't look as complete javascript. Thanks

    
    --- Core/Core.js	2008-06-29 09:09:02.000000000 -0400
    +++ Core/Core-149.js	2008-07-05 16:59:58.000000000 -0400
    @@ -37,6 +37,7 @@
     	object.constructor = Native;
     	object.$family = {name: 'native'};
     	if (legacy && initialize) object.prototype = legacy.prototype;
    +	if (!object.prototype) object.prototype = {};
     	object.prototype.constructor = object;
    
     	if (name){
    
  • WillCz

    WillCz October 4th, 2008 @ 06:12 PM

    Sorry for spam, please ignore previous comment. I understood your code :)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Attachments

Pages