0

I'm trying to inject an iframe into the google home page, in the body.

I use this code to inject into other web pages and it works. Only the google.com website that does not work.

What am I doing wrong?

manifest.json

{
"manifest_version": 2,

   "content_scripts": [ {
      "js": [ "content.js" ],
      "matches": [ "*://*.google.com/*" ]
   } ],

"description": "Inject",

"name": "Inject",
"version": "1.0",
"permissions": [ "*://*.google.com/*", "management", "tabs", "webRequest", "webRequestBlocking" ],
"web_accessible_resources": ["content.html"]
}

content.js

var mhadiv = document.createElement ("iframe");
mhadiv.width = "300px";
mhadiv.height = "300px";
mhadiv.frameBorder = "0";
mhadiv.scrolling = "no";
mhadiv.style.padding = "0";
mhadiv.style.overflow = "hidden";
mhadiv.src = chrome.extension.getURL ("content.html");
document.getElementsByTagName('body')[0].appendChild(mhadiv);

content.html

<html>

<head>


<style type="text/css">

body{
    width: 100%;
    margin:0;
    padding:0;
}

#content {
    width: 300px;
    height: 300px;
    border: 1px solid;
    border-color: #e5e6e9 #dfe0e4 #d0d1d5;
    border-radius: 3px;
    background-color: #fff;
}

</style>

</head>

<body>

<div id="content">

</div>

</body>

</html>
Murilo
  • 49
  • 9
  • Are you sure it works in other pages? `"matches": [ "*://google.com/*" ]` doesn't match any valid url – Haibara Ai Aug 19 '16 at 01:08
  • The character "*" means that the page can be https, http or any other. In this case, I am asking that the content inject just google. Correct me if I'm wrong. @HaibaraAi – Murilo Aug 19 '16 at 01:40
  • You are lacking subdomain name. It should be `"matches": [ "*://*.google.com/*" ]` – Haibara Ai Aug 19 '16 at 01:58
  • Possible duplicate of [What is the URL of the google chrome new tab page and how to exclude it from manifest.json](http://stackoverflow.com/questions/37287333/what-is-the-url-of-the-google-chrome-new-tab-page-and-how-to-exclude-it-from-man) – Haibara Ai Aug 19 '16 at 02:00
  • See above link and you will find how to match chrome new tab page. – Haibara Ai Aug 19 '16 at 02:01
  • Sorry, It was my error when writing the code. I auditioned with the "matches": [ "*://*.google.com/*" ] and it not injected the contents on google. @HaibaraAi – Murilo Aug 19 '16 at 02:55
  • Have you tried above link? `"*://*/_/chrome/newtab*"` – Haibara Ai Aug 19 '16 at 03:34
  • It worked. Another code in the extension did not let inject at the google. My code it is correct, if someone wants to use. Thank you for your help. @HaibaraAi – Murilo Aug 19 '16 at 04:10

0 Answers0