Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page.getPage returns object without functions #131

Open
Reewr opened this issue Apr 22, 2016 · 0 comments
Open

Page.getPage returns object without functions #131

Reewr opened this issue Apr 22, 2016 · 0 comments

Comments

@Reewr
Copy link

Reewr commented Apr 22, 2016

page.getPage(name) can be used to retrieve pages that are children of another page. However, the pages that are retrieved by this function are not node-phantom-simple page instances, but a json-ifined phantom-page.

'use strict';
let driver = require('node-phantom-simple');

let onCreated = function(err, page) {
  page.onPageCreated = function(childPage) {
    childPage.evaluate(function() {
      window.name = 'myName';
    }, function() {
      page.getPage('myName', function(err, newChildPage) {
        console.log('Is null: ', newChildPage === null);
        console.log('Has render:', typeof newChildPage.render !== 'undefined'); 
        console.log(Object.getOwnPropertyNames(newChildPage));
        process.exit();
      });
    });
  };

  page.evaluate(function() {
    window.open(""); // open a blank page
  });
};

let onPhantomCreated = function(err, phantom) {
  phantom.createPage(onCreated);
};

driver.create(onPhantomCreated);

Output:

Is null:  false
Has render: false
[ 'objectName',
  'title',
  'frameTitle',
  'content',
  'frameContent',
  'url',
  'frameUrl',
  'loading',
  'loadingProgress',
  'canGoBack',
  'canGoForward',
  'plainText',
  'framePlainText',
  'libraryPath',
  'offlineStoragePath',
  'offlineStorageQuota',
  'viewportSize',
  'paperSize',
  'clipRect',
  'scrollPosition',
  'navigationLocked',
  'customHeaders',
  'zoomFactor',
  'cookies',
  'windowName',
  'pages',
  'pagesWindowName',
  'ownsPages',
  'framesName',
  'frameName',
  'framesCount',
  'focusedFrameName' ]

As you can see, the object has no actual functions, but only properties that are usually found on the phantom instance of the page.

The same fix you applied to onPageCreated will apply to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant