binaryage / chromex

Write Chrome Extensions in ClojureScript
Other
411 stars 21 forks source link

Is there a context change of some kind? #6

Closed Folcon closed 7 years ago

Folcon commented 7 years ago

I'm currently trying to reproduce a chrome plugin I've written in javascript.

gmail-js is an external dependency that I've managed to load by adding it to the manifest file.

I'm able to test inside the content_script/core.cljs that it is loaded.

However, when I attempt to call one of the methods I get either a method missing error, or an undefined result. This is despite js-keys listing the method in question.

The test I'm doing is trying to call:

gmail.get.user_email();

I've tried calling this the repl:

(.-get.user_email js/gmail)

Which gives me:

#object[Function "function () {
        return api.tracker.globals[10];
    }"]

However trying to log out the same function to js/console just gives me undefined, even though js-keys shows the name "user_email" and logging the result of .-get has the function appearing.

I'm presently wondering if I'm using this correctly? I assumed that I should have things working on the page in the content_script. Am I mistaken?

darwin commented 7 years ago

I'm sorry. You don't understand how Javascript interop works in ClojureScript.

If I understand it correctly, (.get.user_email js/gmail) should make the call.

This is in no way related to chromex.

Folcon commented 7 years ago

No problem

Thanks

darwin commented 7 years ago

Please read this article: http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/

Also maybe consider looking into my other library: https://github.com/binaryage/cljs-oops Where you would call it this way (gcall "gmail.get.user_email" ...)

Folcon commented 7 years ago

Thank you, I've finally worked out what the problem was, I wasn't injecting the script into the page in chromex. Now I just need to work out how to communicate with an injected script as I can't seem to access any of the variables :).