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

Added onInitalized behaviour and fixed unmet dev dependency #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var callbacks = [
'onAuthPrompt'
];

function setup_callbacks(id, page) {
function setup_callbacks(id, page, initCfg) {
callbacks.forEach(function (cb) {
page[cb] = function (parm) {
var args = Array.prototype.slice.call(arguments);
Expand All @@ -165,9 +165,16 @@ function setup_callbacks(id, page) {
var new_id = setup_page(page);
callback_stack.push({ page_id: id, callback: 'onPageCreated', args: [ new_id ] });
};

if (initCfg && initCfg.onInitialized){
page.onInitialized = function (){
// eslint-disable-next-line no-new-func
(Function('return ' + initCfg.onInitialized)())(page, initCfg.onInitializedArgs);
};
}
}

function setup_page(page) {
function setup_page(page, initCfg) {
var id = page_id++;
page.getProperty = function (prop) {
return lookup(page, prop);
Expand Down Expand Up @@ -199,17 +206,17 @@ function setup_page(page) {
return true;
};
pages[id] = page;
setup_callbacks(id, page);
setup_callbacks(id, page, initCfg);
return id;
}

var global_methods = {
setProxy: function (ip, port, proxyType, user, password) {
return phantom.setProxy(ip, port, proxyType, user, password);
},
createPage: function () {
createPage: function (initCfg) {
var page = webpage.create();
var id = setup_page(page);
var id = setup_page(page, initCfg);
return { page_id: id };
},

Expand Down
8 changes: 6 additions & 2 deletions node-phantom-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,12 @@ exports.create = function (options, callback) {
request_queue.push([ [ 0, 'setProxy', ip, port, proxyType, user, password ], callbackOrDummy(callback, poll_func) ]);
},

createPage: function (callback) {
request_queue.push([ [ 0, 'createPage' ], callbackOrDummy(callback, poll_func) ]);
createPage: function (callback, initCfg) {
if (initCfg && initCfg.onInitialized){
initCfg.onInitialized = initCfg.onInitialized.toString();
}

request_queue.push([ [ 0, 'createPage', initCfg ], callbackOrDummy(callback, poll_func) ]);
},

injectJs: function (filename, callback) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"devDependencies": {
"eslint": "^3.4.0",
"mocha": "^3.0.2",
"phantomjs": "^1.9.19"
"phantomjs": "^1.9.19",
"slimerjs": "^0.906.2"
},
"dependencies": {
"debug": "^2.2.0"
Expand Down