FF30+/GM: Need help with exportFunction/cloneInto/createObjectIn

89 views
Skip to first unread message

Aona Nae

unread,
Oct 17, 2014, 5:25:28 AM10/17/14
to greasemon...@googlegroups.com






ajaxChat
.handleChatMessages = function(messageNodes) {


^-- Above as reference. Hey everyone, I'm trying to write a userscript here, and I can't seem to figure out for the life of me, it is day 3 and I looked at examples, researched topics. Constantly refreshed firefox over and over.

I get the feeling that when something in greasemonkey breaks, I don't know about it, I don't know if there's an error in the script. But what I do know is that it works PERFECTLY in Chrome. As that's the browser I mainly use, but when it comes down to porting the script in question I now learned that I need to adhere to the rules of FF's API system.

Which is all fine and dandy, but I want to modify a function at

ajaxChat.handleChatMessages

 since the function is stored in a variable I need to update that variable with a new function.  Perhaps I'm not to be using exportFunction(), but that seems like the appropriate thing. I'm really losing sleep, and my head over this. Firefox has been the most atrocious platform for me to test/develop a userscript on. Is there a way to get the javascript console to be more verbose about errors?

Thanks, if anyone could help me out that'd be much appreciated.

I've been trying to do a exportFunction(ajaxChat.handleChatMessages, unsafeWindow)

But it does not seem to be working. I'm losing it here.

Neil Bird

unread,
Oct 17, 2014, 6:38:37 AM10/17/14
to greasemon...@googlegroups.com
I can't really help much, as I've been bumping up against he same problem.  No use of any of those 3 recommended functions is helping me;  they either fail with obscure codes or just don't work.

All I can say is that I found more output going to Tools/Web Developer/Error Console than was showing up elsewhere (this may be a FireBug window).

I also found the following link:

http://stackoverflow.com/questions/3542609/replacing-page-functions-via-userscript-in-chrome

.. which described actually injecting your function into the page so that is “allowed” to run from other in-page code (since otherwise, IIUC, it's in your elevated-permissions greasemonkey environment).  However, the new function will then not be able to call-back to other GM script functions, or any of the values you declare in the GM script.  That seems to be working for me, since I can get done everything I need to do in page-space within an injected function. (IOW, you'd put your handleCHatMessages assignment within a local inject function, and inject that wrapper inject function).

Aona Nae

unread,
Oct 17, 2014, 7:41:02 AM10/17/14
to greasemon...@googlegroups.com
I really wish I had a better answer than this. It definitely would work. But I was really banking on using GM_Setvalue and all that later in the development process. I'm not able to find the proper documentation, I've found several scripts which use all three of the implementions mentiond. But I am hoping to find someone more experienced in the API and the usage of it. I've spent another whole 7 hours of free time wasted on.. trying figure it out.

Thanks I'll keep your solution in mind. Hoping for a better one really.

Neil Bird

unread,
Oct 17, 2014, 7:48:14 AM10/17/14
to greasemon...@googlegroups.com
I don't know. I /am/ successfully using those set and get value functions from within my script functions that are then attached to click events, but I'm still uncertain as to where the security divide really gets applied.
--
Boring .signature #1,423

Aona Nae

unread,
Oct 17, 2014, 2:39:25 PM10/17/14
to greasemon...@googlegroups.com
if (typeof exportFunction == 'function') {
         
// Doc: http://tinyurl.com/k6qphme
          exportFunction
(function () {}, unsafeWindow, {
            defineAs
: "alert"
         
});
       
} else {
          unsafeWindow
.alert = function () {};
       
}
 That's the closest understanding I have of the code,  but that's for a pre-existing javascript component or function. Not exactly for what im looking for. I may try your idea or your suggestion in a bit. If I can't resolve to find a solution using exportFunction, or any of the other others.
Reply all
Reply to author
Forward
0 new messages