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

How to inject DOM to GMail's user card #12

Open
yorkie opened this issue Sep 26, 2015 · 0 comments
Open

How to inject DOM to GMail's user card #12

yorkie opened this issue Sep 26, 2015 · 0 comments
Labels

Comments

@yorkie
Copy link
Owner

yorkie commented Sep 26, 2015

I was working on chrome plugin for GMail in this week, and at first I'm assigned
to make a tooltip that's shown when an email address is mouse over, and hidden once
move out of that element.

The interaction is same to gmail's user card, so if I was following this, it may be
mess to users because of two "card" that will be shown simultaneously.

Ok, This is the problem that I met in this week, let's address the issue more gracefully.

Caveat

Gmail's user card is an iframe tag within a different domain from gmail's like below:

  • Gmail: mail.google.com
  • UserCard: apis.google.com

So when you try to access that anything in the cross-domain iframe's document by:

document.querySelector('#cross-iframe-id').contentWindow.document;

It will prints the error by chrome:

SecurityError: Blocked a frame with origin "https://mail.google.com" from accessing a cross-origin frame.

This is prohibited by any HTTP browsers of course included chrome, but chrome plugins are the buster.

Plugin Permission

In manifest.json, I just added one domain like this:

{
  ...
  permission: [
    "*://mail.google.com/*",
    "*://apis.google.com/*"
  ],
  ...
}

Okay, then write:

var usercard = document.querySelector('#cross-iframe-id').contentWindow.document;
console.log(usercard);

in your plugin scripts, then run it, now you are able to get document and do any DOM injection based on
this document such as add a line of your company name, change the card avatar etc.

In fact the permission field will be used at firefox add-on, for more details you could visit:
https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/package_json

@yorkie yorkie added the Notes label Sep 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant