wait for angular app to be fully rendered from phantom script

后端 未结 1 1264
醉酒成梦
醉酒成梦 2021-02-08 00:33

I\'m writing a script which generates png images from every page of my frontend. I\'m using angular for the UI and capturing the pages with phantom.

The view take a whil

相关标签:
1条回答
  • 2021-02-08 01:24

    The associated PhantomJS API is onCallback; you can find the API doc on the wiki.

    // in angular
    $scope.$on('$viewContentLoaded', function () {
      window.callPhantom();
    });
    
    // in the phantomjs script
    var page = require('webpage').create();
    page.onCallback = function() {
      page.render('snapshot.png');
      phantom.exit();
    };
    page.open('http://localhost:9000/');
    

    You can get access to the $rootScope by accessing the injector; for example, if you're using the ng-app directive, you can find the element with the directive and call .injector().get("$rootScope") on it. However, I'm not sure if the $viewContentLoaded event will already have fired by then.

    0 讨论(0)
提交回复
热议问题