最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome Extension: Open tab, go to url, fill form and submit form - Stack Overflow

programmeradmin0浏览0评论

I am following a tutorial here /

I can open fine a tab with a custom extension and load a url, and I would like to fill and submit a form with javascript on the page opened. For example, could I submit a search on google?

Here is what I have so far:

manifest.json
{
  "name": "My First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png"
  },
  "background_page": "background.html",
  "permissions": [
    "tabs"
  ]
}

background.html

<script>

// get tab 


chrome.browserAction.onClicked.addListener(function(tab) {
  chrome.tabs.create({'url': ""}, function(tab) {
    // Tab opened. Wait until page loads, from here it is not working
    jQuery(document).ready(function() {
        jQuery('#tsf').submit();
        });
  });
});
</script>

I am following a tutorial here http://www.blackweb20./2010/01/11/creating-your-own-google-chrome-extension/

I can open fine a tab with a custom extension and load a url, and I would like to fill and submit a form with javascript on the page opened. For example, could I submit a search on google.?

Here is what I have so far:

manifest.json
{
  "name": "My First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png"
  },
  "background_page": "background.html",
  "permissions": [
    "tabs"
  ]
}

background.html

<script>

// get tab http://stackoverflow./questions/1979583/how-can-i-get-the-url-for-a-google-chrome-tab


chrome.browserAction.onClicked.addListener(function(tab) {
  chrome.tabs.create({'url': "http://google."}, function(tab) {
    // Tab opened. Wait until page loads, from here it is not working
    jQuery(document).ready(function() {
        jQuery('#tsf').submit();
        });
  });
});
</script>
Share Improve this question edited Nov 18, 2011 at 14:56 giorgio79 asked Nov 18, 2011 at 14:08 giorgio79giorgio79 4,23910 gold badges63 silver badges92 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Your jQuery code is getting executed in the background page not the new tab. Try using chrome.tabs.executeScript to execute the submit in the tab environment.

While you could do this using the chrome extension, I would suggest you to look into Selenium Browser Automation

It will also help you do the same in multiple browser instead of just chrome.

发布评论

评论列表(0)

  1. 暂无评论