Skip to content

Page.getPage returns object without functions #131

Description

@Reewr

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions