Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
917 views
in Technique[技术] by (71.8m points)

node.js - Does PhantomJS store any persistent files by default?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  • On Windows 7: C:Users<user>AppDataLocalOfi LabsPhantomJS
  • On Windows 8: C:Ofi LabsPhantomJs
  • 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...