Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to find the cache folder used by phantomjs? #17

Closed
jamesliu668 opened this issue Sep 27, 2017 · 4 comments
Closed

How to find the cache folder used by phantomjs? #17

jamesliu668 opened this issue Sep 27, 2017 · 4 comments

Comments

@jamesliu668
Copy link

Hello admin,

Here I have a question about the phantomjs cache folder. I know there is an option to set the disk cache path, which I can set the cache folder like this:

phantomjs --disk-cache=true --load-images=false --disk-cache-path=./ simpletest.js
With above command, I will get a data8 on my working path. After several hours searching on Google, I only find that phantomjs will create cache folder under the disk-cache-path folder, the cache folder name could be one of data1 to dataF (16 options).

So my problem is how can I what the exact folder will hold the cache file.

Best Regards
James

@iradul
Copy link
Owner

iradul commented Oct 2, 2017

Your launch.json probably looks like this:

...
"runtimeArgs": ["--load-images=false", "--disk-cache=true", "--disk-cache-path=./"],
...

Since you're passing --disk-cache-path=./, cache directories will be created under current directory which for debugger is directory where Code is installed. You should use absolute path instead of relative, for example --disk-cache-path=c:\\phantom-cashe\\.
Take a look at this similar issue #11

@iradul iradul closed this as completed Oct 2, 2017
@jamesliu668
Copy link
Author

@iradul

Thank you for reply. The option --disk-cache-path=./ only tells where to create cache directories. However, under folder current folder (./), the real cache folder will be like data1, data2.....dataF. The exact cache folder could be any one of them. So my question is, how can I know the exact cache folder where the cache files are located.

My current project needs to save js and css files along with html content, so I need to read them from cache folder and save them by this way:
https://stackoverflow.com/questions/11531448/grab-the-resource-contents-in-casperjs-or-phantomjs (in the second solution with cache.js and mimetype.js)
https://gist.github.com/bshamric/4717583

In my current project, I am writing the code to read cache file from data8 folder by hard-code. What's the programmatically way to get the right datax folder, and what the x is.

Best Regards
James

@iradul
Copy link
Owner

iradul commented Oct 16, 2017

Unfortunately this issues tracker is only meant for PhantomJS debugger plugin for VSCode. Your question is related to PhantomJS itself.

I suggest that you look for an answer elsewhere like:
https://groups.google.com/forum/#!forum/phantomjs
https://github.com/ariya/phantomjs/issues

Anyway what you could probably do is something like this:

  1. hook a handler on onResourceRequested or onResourceReceived of your page instance
  2. save URL of any js or css that your page is requesting
  3. use another page2 instance and load this URL into it with page2.open() method
  4. read the content with page2.content (you'll probably also need to clean up some html tags but js/css content will be there)

@jamesliu668
Copy link
Author

Oh, I am sorry. That's my fault. But thank you for your patient to answer my questions. The solution is real a way to solve my question, though it could load the resource twice.

You are awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants