Does PhantomJS store any persistent files by default?

喜你入骨 提交于 2019-12-18 09:28:02

问题


As a new user to PhantomJS I want to be sure that I understand how PhantomJS handles any persistence of data that it accumulates from a HTTP request.

My question is: Does PhantomJS store any data persistently by default (i.e. a simple example where you are not using require('fs') anywhere in the script to store the request, just dumping it out to STDOUT). I am assuming that all of the work from a page.evaluate() call is done in memory.

Here is a simple example for illustration:

var page = require('webpage').create(),
system = require('system'),
address;

if(system.args.length != 2)
{
    console.log('Usage: phantomjs thisFile.js URL');
    phantom.exit(1);
}
else
{
    address = system.args[1];

    page.open(address, function (status)
    {
        if(status !== 'success')
        {
            console.log('Unable to load the address!');
            phantom.exit(1);
        }
        else
        {
            // Wait for the js to finish loading
            window.setTimeout(function(){
                var results = page.evaluate(function(){
                    return document.documentElement.innerHTML;
                });

                console.log(results); // This would be to stdout

                phantom.exit(0);
            }, 200);
        }
        console.log("Done.");
    });
}

This script would be called by something like phantomjs thisScript.js www.example.com.

I know that you can save a page to file, I just want to be sure that I am aware of all the places that PhantomJS may accumulate data on its own.

I also have looked into how PhantomJS handles cookies.


回答1:


Yes, there is one type that is saved by default and this is the localStorage database.

  • On Windows 7: C:\Users\<user>\AppData\Local\Ofi Labs\PhantomJS
  • On Windows 8: C:\Ofi Labs\PhantomJs
  • On Linux: /home/<user>/.qws/share/data/Ofi Labs/PhantomJS

Everything else is saved only when you add the commandline options. The disk cache is inside of the above directory and the cookie file path has to be set explicitly.

So it means that if the web application that you test doesn't use localStorage then you can run PhantomJS in parallel.



来源:https://stackoverflow.com/questions/27023093/does-phantomjs-store-any-persistent-files-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!