How to replace a navigator object with a popup in CasperJS?

How can I replace a navigator object in a popup?

I can replace the navigator with page.initializedcallback, but it does not affect the pop-ups.

In PhantomJS, I can use something like this:

page.onPageCreated = function (newPage) {
  newPage.onInitialized = function () {
    newPage.evaluate(function() {
      window.navigator = {/*some code*/}
    });
  }
};

How to do it on CasperJS?

+4
source share
1 answer

CasperJS is built on top of PhantomJS. If he works in PhantomJS, then he will also work in CasperJS.

  • You can either directly contact to casper.pagerun the same code as in PhantomJS or

  • You can use popup.createdan event handler to do the same in CasperJS:

    casper.on("popup.created", function (newPage) {
      newPage.onInitialized = function () {
        newPage.evaluate(function() {
          window.navigator = {/*some code*/}
        });
      }
    });
    
0

All Articles