Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 3 of 3

This is a discussion on chrome.create.tabs not working within the Chrome Tech section, part of the Chrome Chat category: Hi, My extension needs to find a link in the loaded facebook page, and then open this link in a ...


  1. #1
    nabeca is offline Junior Member
    Join Date
    Sep 2010
    Posts
    2

    Default chrome.create.tabs not working

    Hi,

    My extension needs to find a link in the loaded facebook page, and then open this link in a new tab. I cannot get it work. Please help me locate what i am doing wrong.

    contentscript.js
    Code:
    var regex = /facebook.com\/friends\//;
    
    // Test the text of the body element against our regular expression.
    if (regex.test(document.body.innerHTML)) {
       //I tried chrome.tabs.create as well
       chrome.tabs.createTab({'url': 'http://search.twitter.com/'}, function(){});
      // The regular expression produced a match, so notify the background page.
      chrome.extension.sendRequest({}, function(response) {});
    } else {
      // No match was found.
    }
    Here is the manifest
    Code:
    {
      "name" : "Page action by content",
      "version" : "1.0",
      "description" : "Shows a page action for HTML pages containing the word 'sandwich'",
      "background_page" : "background.html",
      "permissions": [
      "tabs",
      "http://search.twitter.com/"
      ],
      "page_action" :
      {
        "default_icon" : "sandwich-19.png",
        "default_title" : "found something!"
      },
      "content_scripts" : [
        {
          "matches" : [
            "http://*/*",
            "https://*/*"
          ],
          "js" : ["contentscript.js"],
          "run_at" : "document_idle",
          "all_frames" : false
        }
      ],
      "icons" : {
        "48" : "sandwich-48.png",
        "128" : "sandwich-128.png"
      }
    }
    and here is the background.html
    Code:
    <!DOCTYPE html>
    <!--
     * Copyright (c) 2010 The Chromium Authors. All rights reserved.  Use of this
     * source code is governed by a BSD-style license that can be found in the
     * LICENSE file.
    -->
    <html>
      <head>
        <script>
          // Called when a message is passed.  We assume that the content script
          // wants to show the page action.
          function onRequest(request, sender, sendResponse) {
            // Show the page action for the tab that the sender (content script)
            // was on.
            chrome.pageAction.show(sender.tab.id);
    
            // Return nothing to let the connection be cleaned up.
            sendResponse({});
          };
    
          // Listen for the content script to send a message to the background page.
          chrome.extension.onRequest.addListener(onRequest);
        </script>
      </head>
    </html>

  2. #2
    nabeca is offline Junior Member
    Join Date
    Sep 2010
    Posts
    2

    Default

    Okay, I found what was wrong. i will share it here so people can see it, also it shows up in google queries.

    Chrome.tabs.create not working, not opening problem.

    You will have to cary the action from the contentscript.js file to the background.html. chrome.tabs.create can only be called from the background.html. It will not work in javascript files. so the new background.html file should look like this:
    Code:
    <html>
      <head>
        <script>
          // Called when a message is passed.  We assume that the content script
          // wants to show the page action.
          function onRequest(request, sender, sendResponse) {
            // Show the page action for the tab that the sender (content script)
            // was on.
            chrome.pageAction.show(sender.tab.id);
    		
    		chrome.tabs.create({"url":"http://www.google.com"}); 
            // Return nothing to let the connection be cleaned up.
            sendResponse({});
          };
    	 
          // Listen for the content script to send a message to the background page.
          chrome.extension.onRequest.addListener(onRequest);
        </script>
      </head>
    </html>

  3. #3
    thisisbasil is offline Junior Member
    Join Date
    Sep 2010
    Posts
    3

    Default

    im having a similar problem

    i have a plugin that takes user input from a popup.html from the the toolbar, calls a NPAPI dll with the user input, and that dll creates a local XML file. i want to open a new tab with the generated XML file immediately after the retun from the NPAPI call. any ideas on how to do this?

Similar Threads

  1. How to create a new theme for Chrome 3.0.196.2 for newbies
    By sulasno in forum Themes Troubleshooting
    Replies: 5
    Last Post: 01-12-2011, 12:31 PM
  2. Unable to create new tabs via CTRL+T while watching Youtube vids
    By Silentlee in forum Chrome Troubleshooting
    Replies: 1
    Last Post: 09-01-2010, 05:20 AM
  3. Looking to create an Extension for Chrome
    By dpsubi1 in forum Plugins Development
    Replies: 3
    Last Post: 05-28-2010, 06:44 PM
  4. How to create a new theme for Stable / Beta / Dev Chrome
    By sulasno in forum Themes Development
    Replies: 24
    Last Post: 12-03-2009, 10:48 PM
  5. chrome.tabs.create problem
    By Inco in forum Plugins Development
    Replies: 1
    Last Post: 11-09-2009, 07:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •