0

I have a chrome extension that needs to parse several pages on a domain. I normally do this by using a background XHR and then send the response into jquery.

$(xhr.responseText)

However, the response from the XHR does not contain all the HTML and JQuery is not processing the dynamic content. The pages use AngluarJS ng-view and that portion of the page is not populating. The data can not be queried directly as it appears to be proxied.

Simplified XHR response minus js:

<html lang="en" ng-app="ngApp" id="ng-app" ng-class="viewName">
    <body ng-controller="AppController">
        <div class="container-fluid" id="maincontent" tabindex="-1">
            <div ng-view autoscroll="true" data-ng-animate="{{viewAnimation}}"></div>
        </div>
    </body>
</html>

I've spent days reviewing these pages - can't figure it out, AngularJS is foreign to me. Can't get $compile to work, property of invoke undefined, and other hair pulling. I'm lost.

Is there a way to have a chrome extension process the XHR return to capture the remaining dynamic code?

Community
  • 1
  • 1
ElJeffe
  • 637
  • 1
  • 8
  • 20
  • You can try adding an iframe in the background page DOM for the remote site and [strip its X-Frame-Options](http://stackoverflow.com/questions/15532791/getting-around-x-frame-options-deny-in-a-chrome-extension), then extract the processed html in onload + timeout or MutationObserver to catch the moment when DOM was dynamically updated by the page script. – wOxxOm Feb 26 '17 at 18:01
  • I was able to load the iframe I think in the background, but I'm running into cross-origin issues trying to read the DOM. – ElJeffe Feb 27 '17 at 02:28
  • Add the URL you need to access to "permissions" key in manifest, see the docs for an example. Or ``. – wOxxOm Feb 27 '17 at 05:55
  • Already had, permissions don't appear to work for iframe. According to a comment on this post http://stackoverflow.com/questions/5724135/creating-a-hidden-iframe-in-a-chrome-extension permission "only applies to cross-origin XMLHttpRequests, injecting content scripts, and reading cookies. It does not apply to reading an iframe within a background page." Looking at maybe trying a content script in the iframe. http://stackoverflow.com/questions/40248467/chrome-extension-accessing-a-cross-origin-iframe-within-background-html – ElJeffe Feb 27 '17 at 12:26

0 Answers0