开发者

Extensions Issue - ContentScript & Premissions for an overlay

I'm currently developing an overlay for Google Chrome (A toolbar if you prefer), and i have some issues with and i can't understand the reason why.

So, basically i've created an extension with this manifest.json :

{   

    "background_page" : "background.html",
    "browser_action" :
    {
        "default_icon" : "images/Extension.png"
    },
    "content_scripts": 
    [ {
      "all_frames": true,
      "css": ["css/overlay.css"],
      "js": ["js/overlay.js"],
      "matches": ["http://*/*"],
      "run_at": "document_start"
    } ], 
    "permissions" : ["tabs", "unlimitedStorage", "http://*/*"], 
    "name" : "MyOverlay",
    "version" : "1.1",
    "description" : "Sindar Overlay"
}

The concept is that my background.html page will call the jquery.js and overlay.js. Then on the initialization of overlay.js it will call the html page (overlay.html) by using

<iframe id="YourToolbarFrame" src="'+toolbarURL+'">

The problem is that when i'm trying to start the extension everything seem to be good, no compilation problem but i don't see my overlay. And when i'm just opening the html page all is ok, i see it. So i'm asking myself if the problem dont come from the contentscript or from the permissions but i dont know where it could come from...

Thanks in advance.

Edit 23/02/2011 - 18:46

background.html

<html>
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script src="js/overlay.js"></script>
  </head>
</html>

overlay.js

var overlay= {
    init: function() {
        this.injectoverlay();
        //alert('Initialisation reussie');
    },

    injectoverlay: function() {
        var body = $('body'),
            overlayURL = chrome.extension.getURL("overlay.html"),
            iframe = $('<iframe id="YouroverlayFrame" src="'+overlayURL+'">');

            body.append(iframe);
            iframe.show();

        //alert('Injection reussie');
    }
}

var length = {}, maxLength = 0, currentLength;

$(function(){
$('#menu li.title')
   .each(function(){
        // Save the Menu Length
        length[$(this).attr('id')] = currentLength = $(this).height();

        // Fix the height
        $(this).height(20);

        if(currentLength > maxLength)
        {
            maxLength = currentLength;
        }

        // To don't overflow on the content
        $('#menu').height(maxLength);
   })

   .mouseenter(function(){
        $(this).stop().animate({
            height: length[$(this).attr('id')]
        }, 500);
   })
   .mouseleave(function(){
       $(this).stop().animate({
           height: '20px'
       }, 500);      
   });
});

$(document).ready(function() {
    overlay.init();
});

overlay.html

<html>
  <head>
        <title>overlay</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link rel="stylesheet" href="css/overlay.css" type="text/css"></link>
        <base target="_blank" />
    </head>
    <body>
        <div class="default">
            <form id="searchForm">
                <img id="logo" src="images/Extension.png"></img>
                <input type="search" value="Enter you research" name="search">
                <input type="submit" value="Go !" /> |
            </form>

            <ul id="menu">
                <!--
                <li class="title" id="accueil">
                    <a class="" href="#">Accueil</a>
                </li>
                -->
                <li class="title" id="contact">
                    <a class="" href="#">Contact</a>
                    <ul class="dropMenu">
                        <li><a href="www.google.com">google</a></li>
                        <li><a href="www.yahoo.com">yahoo</a></li>
                    </ul>
                </li>
            </ul>
        </div>

        <!--    Include the library of Google, more centralized.
                Optimized the browser cache.
                Compressed version. -->

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.开发者_开发问答min.js"></script>

    </body>
</html>


Currently you include overlay.js as a content script to all pages plus include it into a background page for some reason. You don't need a background page for this task. If you are doing this just to inject jquery the solution would be to download jquery.js and put it into your extension folder, then automatically inject it in the manifest.json:

//"background_page" : "background.html", - this is not needed
"content_scripts": 
    [ {
      "all_frames": true,
      "css": ["css/overlay.css"],
      "js": ["js/jquery.js", "js/overlay.js"], //jquery included as well
      "matches": ["http://*/*"],
      "run_at": "document_start"
    } ], 

(besides a background page doesn't have visible body, so you inject your frame to an invisible page right now)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜