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
Here is the manifestCode: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. }
and here is the background.htmlCode:{ "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" } }
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>


LinkBack URL
About LinkBacks



Reply With Quote