How to access Content from a pop up in google chrome extension

Go To StackoverFlow.com

1

I am developing a simple page action extension in google chrome and it has the following purpose.

  1. Show a pop-up on click and prompt for username and password.
  2. After a small validation, it should fill the username and password for the website, like gmail.com.

I saw couple of examples on how to do that on window load and I was able to do a pop-up separately. But I am not able to access the parent html from the pop-up's html.

Any help would be highly appreciated.

Here are the contents of my code.

Manifest.json:

{
  "name": "My First Chrome App",
  "version": "1.0",
  "description": "Auto fill content",
  "background": { "scripts": ["background.js"] },
  "page_action" :
  {
    "default_icon" : "icon-19.png",
    "default_title" : "Auto Fill",
    "default_popup" : "test.html"   
  },
  "permissions" : [
  "tabs"
  ],
  "icons" : {
    "48" : "icon-48.png",
    "128" : "icon-128.png"
  },
  "manifest_version": 2 
}

background.js

function checkForValidUrl(tabId, changeInfo, tab) {
  //checks whether the document contains Steve Jobs
  if (tab.url.indexOf("gmail")) {
    chrome.pageAction.show(tabId);
  }
};
chrome.tabs.onUpdated.addListener(checkForValidUrl);

test.html

<html>
<head>
    <title> Hi Steve </title>
    <script type="text/javascript">
        function fill()
        {
            alert("inside method");         
        }
    </script>
</head>
<body>
    <form name="userinfo" id="userinfo">
        username : 
        <input type="text" name="username"/>
        password :
        <input type="password" name="password"/>
        <input type="button" value="Log In" onclick="fill()";/>
    </form>
</body>
</html>

Thanks, Shankar

2012-04-04 19:39
by Shankar


1

Create a popup window for your login that has the username and password fields.

http://code.google.com/chrome/extensions/browserAction.html#popups

When the popup form is submitted send a message to the background page which then sends a message to your (page's) content script which is then responsible for filling out and submitting the form.

http://code.google.com/chrome/extensions/content_scripts.html

You'll need to understand message passing to do this:

http://code.google.com/chrome/extensions/messaging.html

2012-04-06 23:18
by Richard Hollis
Thanks a lot Richard. I will try the same and get back if I am having any difficulties - Shankar 2012-04-07 17:57
Ads