Skip to content
This repository has been archived by the owner on Dec 4, 2019. It is now read-only.

Latest commit

 

History

History
42 lines (32 loc) · 942 Bytes

advanced.md

File metadata and controls

42 lines (32 loc) · 942 Bytes

Advanced

Methods below are for advanced users. Most people won't need these methods.

page.defineMethod

A method can be defined using the #defineMethod(name, definition) method.

page.defineMethod('getZoomFactor', function() {
	return this.zoomFactor;
});

page.invokeAsyncMethod

An asynchronous method can be invoked using the #invokeAsyncMethod(method, arg1, arg2, arg3...) method.

page.invokeAsyncMethod('open', 'http://phantomjs.org/').then(function(status) {
	console.log(status);
});

page.invokeMethod

A method can be invoked using the #invokeMethod(method, arg1, arg2, arg3...) method.

page.invokeMethod('evaluate', function() {
	return document.title;
}).then(function(title) {
	console.log(title);
});
page.invokeMethod('evaluate', function(selector) {
	return document.querySelector(selector) !== null;
}, '#element').then(function(exists) {
	console.log(exists);
});