Chrome Extension to execute JQuery script on about:blank page

1,595 views
Skip to first unread message

anandsagar sah

unread,
Feb 22, 2014, 5:12:04 AM2/22/14
to chromium-...@chromium.org

I have a very specific requirement with chrome extension, Please suggest any possible way to achieve it. I have provided enough details below, but let me know any more is required.

Requirement: I have a page with content on about:blank page. I want chrome extension to execute JQuery scripts on user request (like from context menu item)

Detail: I have a web application, which has a option to enable the log. When the log is turn on, the new log window pops up(about:blank URL) and application starts pushing data on that window. I want to write extension on that poped up window, but the problem is content scripts doesn't run (as designed?) on about:blank. Screenshot of application pushing data on popup window (about:blank page):http://postimg.org/image/4nu8goa2t/ 

What I have done so far? I wrote a extension which performs  $("body").hide() from the context menu, with lot of alerts. This works fine on http/s pages. but not on about:blank. detailed below.

What exactly I want from the requirement? The content on logging window is not user friendly, so all I want is to write JQuery to modify DOM of popup window, give nice navigation, do color highlighting etc... i.e. all functionality of JQuery as content script on about:blank page.

If running content script on about:blank page is not possible, at least I want my extension to copy the about:blank page content, paste it on new tab and apply jquery scripts there to achieve the requirement.

But it seems all my attempt has failed: Below is the script: backgroud.js

    alert("Extension loaded");
    function genericOnClick(info, tab) {
        chrome.tabs.executeScript({
            code: 'alert(document.getElementById("logWindowId").innerHTML)'
        }); 
        alert(tab.title);
        chrome.tabs.executeScript(tab.id, {
                file: "jquery.min.js",
                allFrames: true
            },function(){
                alert("Executing Sample.js");

                chrome.tabs.executeScript(tab.id, {
                    file: "sample.js",
                    allFrames: true
            });
        });
    }
    var contexts = ["page"];

      var context = contexts[0];
      var title = "Test Page menu item";
      var id = chrome.contextMenus.create({"title": title, "contexts":[context],
                                           "onclick": genericOnClick});

content.js

alert(document.getElementById("logWindowId").innerHTML);
alert("Now I will hide the body");
$("body").hide();

json file

 {
 "manifest_version": 2,
  "name": "jQuery DOM",
  "version": "1",
  "permissions": [
    "contextMenus","tabs","activeTab"
  ],
  "background": {
    "scripts": ["jquery.min.js","background.js"]
  },
  "description": "Manipulate the DOM when the page is done loading",
  "browser_action": {
    "name": "Manipulate DOM",
    "icons": ["icon.png"],
    "default_icon": "icon.png"
  }
}

All the alerts work fine on http/s page, but alerts from both chrome.tabs.executeScript failed. Event API chrome.tabs.duplicate(integer tabId, function callback) failed, it just open another blank page, but doesn't really copy the content.

Please provide your expert suggestion here.

anandsagar sah

unread,
Feb 24, 2014, 9:56:57 AM2/24/14
to chromium-...@chromium.org
Can any one please help here ?

bc guo

unread,
Apr 16, 2024, 5:12:47 AM4/16/24
to Chromium Extensions, anandsagar sah

So how did you solve this problem?
Reply all
Reply to author
Forward
0 new messages