Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhantomJS incognito mode

Tags:

phantomjs

Is there a way I can do the equivalent of "incognito mode" with PhantomJS, where all cookies, local storage, etc., is only transient and does not persist across processes?

This would be useful for UI automation as well as some back-end applications.

like image 492
wrschneider Avatar asked Nov 01 '22 00:11

wrschneider


1 Answers

No, there is no such thing out-of-the-box, but at least there are things you can do for some types of data.

Cache and cookies are by default only visible for one phantom instance, but they can be enabled by setting the files for them from the commandline. So you're good here.

The other problematic features are applicationCache, localStorage and webSQLDatabase determined by running modernizr test suite from phantom.

applicationCache is not really a problem as in most cases only public data is cached. It cannot be cleared after each run.

localStorage can be cleared after each run using localStorage.clear() (see here), provided you run your tests sequentially. This might not be the case as you probably use multiple processes in parallel to execute faster. No real solution here.

webSQLDatabase still can not be cleared: How to delete a database in Web SQL?

It's sad to say that there are multiple issues with session handling.

like image 115
Artjom B. Avatar answered Nov 08 '22 09:11

Artjom B.