I’m unfamiliar with Javascript and have been struggling to understand how I’d go about displaying the page_action icon when a specific URL is opened in a tab.
I’ve attempted to use some of the samples provided by Google to find specific letters in the URL (their example uses ‘g’). I even tried simply using their extension unpacked and it didn’t work for me when I visit Google.
// Copyright (c) 2011 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.
// Called when the url of a tab changes.
function checkForValidUrl(tabId, changeInfo, tab) {
// If the letter 'g' is found in the tab's URL...
if (tab.url.indexOf('g') > -1) {
// ... show the page action.
chrome.pageAction.show(tabId);
}
};
// Listen for any changes to the URL of any tab.
chrome.tabs.onUpdated.addListener(checkForValidUrl);
Am I missing something incredibly obvious?
This example is not working for me either. I contacted the author of this example and got this response:
To fix it, create simple html page (name it
background.html) that only loads javascript:Then, change one line in the
manifest.json, from:to:
Remember to reload your extension in a browser after these changes.
That will not only work but also will allow you to debug your code:
background.htmlto debug it