phantomjs --version.2.5.0-development
i. Create a JavaScript file check-local-storage.js, such as:
'use strict';
var page = require('webpage').create();
page.open('http://example.com', function() {
var ls = page.evaluate(function() {
return String(window.localStorage);
});
console.log(ls);
phantom.exit();
});
ii. Run the script with PhantomJS v2.5.0-development.
$ phantomjs --version
> 2.5.0-development
$ phantomjs check-local-storage.js
> null
As you can see, in 2.5.0-development window.localStorage is not a valid object and we can't use its methods – clear, getItem, setItem etc.
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.12.2
BuildVersion: 16C67
The binary downloaded from https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.5.0-beta-macos.zip.
With the latest stable version v2.1.1 installed via Homebrew, the code above prints the expected behavior. So, this bug was certainly introduced in v2.5.0-development.
$ phantomjs --version
> 2.1.1
$ phantomjs check-local-storage.js
> [object Storage]
Since 2.5 (or this commit https://github.com/ariya/phantomjs/commit/fc57497166b85678d5a6616019c8c21139b74d05) localStorage disabled by default. This change was introduced to make PhantomJS portable as much as possible. To enable localStorage you have to set its quota >= 0, e.g.:
phantomjs --local-storage-quota=5000
We also have plans on moving configuration options to a default configuration file, so you will need to specify default options once.
How will I be able to enable the localStorage via OpenQA.Selenium.PhantomJS?
I'm using the 2.5.0-development version for Selenium C# testing and the testing web application is causing issues as localStorage is disabled.
How to set local-storage-quota via Selenium WebDriver:
```c#
PhantomJSDriverService driverService = PhantomJSDriverService.CreateDefaultService();
driverService.LocalStorageQuota = 5000;
PhantomJSDriver driver = new PhantomJSDriver(driverService);
```
@GopianiS ghostdriver does not support local storage or session storage apis. see detro/ghostdriver#25 and detro/ghostdriver#26.
i don't see it in the w3c specification so you would have to follow https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol. you can implement it by delegating to selenium atoms.
@Vitallium I have ran into this same issue, however, I am doing this through Selenium Webdriver. It seems that I need both --local-storage-quota and --local-storage-path. The quota alone did not work. Is this expected?
@GopianiS Sample code:
DesiredCapabilities phantomBilities = DesiredCapabilities.phantomjs();
phantomBilities.setCapability("phantomjs.cli.args",
new String[] { "--ignore-ssl-errors=true", "--local-storage-quota=5000",
"--local-storage-path=" + Files.createTempDirectory("PhantomLocalStorage-").toString() });
return new PhantomJSDriver(phantomBilities);
How can I run phantomjs with a flag --local-storage-quota=5000 when running on casperjs?
@nirpeled were you able to figure this out with casperjs?
@AlexKopen I'm afraid not, I decided to switch to cypress.io
Most helpful comment
Since 2.5 (or this commit https://github.com/ariya/phantomjs/commit/fc57497166b85678d5a6616019c8c21139b74d05)
localStoragedisabled by default. This change was introduced to make PhantomJS portable as much as possible. To enablelocalStorageyou have to set its quota >= 0, e.g.:We also have plans on moving configuration options to a default configuration file, so you will need to specify default options once.