- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- PhantomJS - Properties
- PhantomJS - Methods
- PhantomJS - Events/Callbacks
- PhantomJS - Child Process Module
- File System Module
- PhantomJS - Properties
- PhantomJS - Methods
- System Module
- PhantomJS - Properties
- Web Server Module
- PhantomJS - Properties
- PhantomJS - Methods
- Miscellaneous
- Command Line Interface
- PhantomJS - Screen Capture
- PhantomJS - Page Automation
- PhantomJS - Network Monitoring
- PhantomJS - Testing
- PhantomJS - REPL
- PhantomJS - Examples
- PhantomJS Useful Resources
- PhantomJS - Quick Guide
- PhantomJS - Useful Resources
- PhantomJS - Discussion
PhantomJS - clearCookies()
The ClearCookies () method will delete all the cookies for the page specified.
Syntax
Its syntax is as follows −
wpage.clearCookies();
Example
Let us look at an example of the clearCookies () method.
var wpage = require('webpage').create();
phantom.addCookie ({
'name' : 'cookie1', /* mandatory property */
'value' : '1234', /* mandatory property */
'domain' : 'localhost', /* mandatory property */
'path' : '/',
'httponly' : true,
'secure' : false,
'expires' : (new Date()).getTime() + (5000 * 60 * 60)
});
wpage.open ('http://localhost/tasks/a.html', function() {
console.log("Cookies available are :");
console.log(JSON.stringify(wpage.cookies));
console.log("Clearing all cookies");
wpage.clearCookies();
console.log("Cookies available now");
console.log(JSON.stringify(wpage.cookies));
phantom.exit();
});
The above program generates the following output.
Cookies available are :
[{"domain":".localhost","expires":"Sun, 07 May 2017 01:28:18 GMT","expiry":14941
00698,"httponly":true,"name":"cookie1","path":"/","secure":false,"value":"1234" }
,{"domain":"localhost","expires":"Fri, 22 Dec 2017 12:00:00 GMT","expiry":151394
4000,"httponly":false,"name":"username","path":"/tasks/","secure":false,"value" :
"Roy"}]
Clearing all cookies
Cookies available now
[]
phantomjs_webpage_module_methods.htm
Advertisements