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

Using dart:js and Google's javascript #52

Open
Goutte opened this issue Apr 9, 2014 · 9 comments
Open

Using dart:js and Google's javascript #52

Goutte opened this issue Apr 9, 2014 · 9 comments

Comments

@Goutte
Copy link

Goutte commented Apr 9, 2014

Load this in the page :

<script type="text/javascript">
  // https://developers.google.com/+/web/share/interactive
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/client:plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>

When using new GoogleOAuth2(client_id, scopes); and then login, I get the cryptic :

Uncaught TypeError: Cannot call method 'replace' of undefined
(anonymous function) cb=gapi.loaded_0:464
(anonymous function) cb=gapi.loaded_0:459
g cb=gapi.loaded_0:63
c

... which is in the js loaded by https://apis.google.com/js/client:plusone.js ?
A Dart call makes a js lib fail.
Is it just me ?

I have dart:js imported as well, as I'm trying down the road to :

context['gapi']['interactivepost'].callMethod('render', ['google_plus_boast', share_options]);

but I'm not even there yet. This issue has too much shadows for me, can anyone shine some light ?


google_oauth2_client: '>=0.2.18 <1.0.0'
Dartium Version 31.0.1650.48 custom (240209).

@adam-singer
Copy link
Member

@Goutte The latest oauth2 client is:

dependencies:
  google_oauth2_client: ">=0.3.7 <0.4.0"

Can you let us know if the issue still happens after upgrading?

@Goutte
Copy link
Author

Goutte commented Apr 10, 2014

@financecoding Thanks for the interest !

I'm using 0.3.7 already, pub says. I capped the deps interval at 1.0.0 instead of 0.4.0 because of major BC breaks that usually go with major version bumps. Minor version bumps keep a dev on its toes. :)

@Goutte
Copy link
Author

Goutte commented Apr 11, 2014

The exception occurs within a callback registered to "oauth2relayReady", or "oauth2callback", it's hard to say. (minified js)

I see GoogleOAuth2 subscribing to these events in _createFutureChannel, but I can't find the code that fires them.

@adam-singer
Copy link
Member

@Goutte so it is happening with the latest version of the library?

@Goutte
Copy link
Author

Goutte commented Apr 12, 2014

@financecoding Yes.

Further inquiry reveals that the attribute state is missing from a variable in google's listener.
I'm stuck again, still can't find the code that fires the events, and do not know how to report to google that their listener does not play well with others.

@Goutte
Copy link
Author

Goutte commented Apr 13, 2014

The variable (whose state attribute is missing) actually contains :

access_token: "ja29.1.AADtN_XLk8CpZK1WS1mq6TswNsRgYa5efzJNI8QuPJbZwGaN4LhCWccph2iZ8OJgCw-orujuG2Z7PlZ5RJZnSdnrh7z7-cQ61XVDKfP-pPwurbKOxkFG-jx_UgUo8U7yPg"
authuser: "0"
expires_in: "3600"
num_sessions: "1"
prompt: "none"
session_state: "2dca566abd59b2e10c277cd11d00e4153db27655..9379"
token_type: "Bearer"

Google is trying to a.state.replace(/\|.*$/,"") (remove all trailing characters after the pipe, included) in the attribute state (which is undefined, hence the error). We have session_state defined, I wonder if this is what it is looking for ?

@Scarygami
Copy link
Member

Hmmm... that's a weird error. It might be that gapi is also listening for the auth window and both methods trying to catch the token at the same time is causing this issue.

Since you are using gapi anyway I would suggest using the gapi-provided Google+ Sign-in button for authentication, and using SimpleOAuth2 for accessing APIs if you need it, passing in the access token you get in the js auth callback.

See https://github.com/dart-gde/gplus-quickstart-dart/tree/master/client-side/web for a sample implementation of this.

@Goutte
Copy link
Author

Goutte commented Apr 14, 2014

@Scarygami Thanks a lot for the example link, it's handy !

Yes, gapi is listening on the infamous message event : window.addEventListener("message",a,!1). I'm wondering if someone at google sold to the minifying team the horrible practice of !1, arguing, charts and data handy, that it was more profitable to shave off these few bytes even if it taxes clients ?
When you can't know, observe those who can ?

Anyway, I will have to recede, as you suggested, on the usage of GoogleOAuth2.
I don't know if I should close this issue, as it's obviously something for google but it might help anyone coming after me.


On another note, looking at the examples...

Is there any reason for keeping:

<script type="text/javascript">
      (function() {
       var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
       po.src = 'https://apis.google.com/js/client:plusone.js';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
     })();
</script>

instead of

ScriptElement script = new ScriptElement();
script.async = true;
script.type = "text/javascript";
script.src = "https://plus.google.com/js/client:plusone.js";
document.body.children.add(script);

?

I'm more than tempted to use the second solution ! (embedding of dart code before and after, maybe a Future for when loaded ?)

@Scarygami
Copy link
Member

No reason for doing the script loading in JavaScript. I prefer to do it directly in Dart as well.

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