views:

110

answers:

1

I'm in the process of making a Google Chrome extension, and encountered a problem.

I'm trying to upload and search through the DOM inside the popup.html.

Here is how I get the current tab (I found the script somewhere, credit doesn't belong to me):

 chrome.windows.getCurrent(function(w) {
      chrome.tabs.getSelected(w.id,function (response){
  )};

My problem is this: I need to traverse through the DOM of the response. When trying to do so manually, I couldn't, as the response variable was now undefined for some reason, so using the Console isn't an option. When trying to alert the response in the html file, it came as a object. Then, I tried to navigate through the response as if it has been the 'document' object, but no luck either.

Any help will be appreciated greatly.

A: 

I believe popups are sandboxed the same way that background pages are, so you'll need to use a content script to access the page DOM.

You can inject a content script with chrome.tabs.executeScript, handle your DOM traversal in the content script, then pass back the information you need from the content script to the popup using the message passing API.

I can try to elaborate on this if you give more information about the problem you're trying to solve.

Greg