简体   繁体   中英

localStorage.getItem() gives a different result in different browsers

I am working with PhantomJS. I want to compare the behavior of PhantomJS with Google Chrome while loading the first page of WikiPedia. Based on my observation there is a request generated by both browsers which is triggering differently. There is a parameter in that request which takes a different value in each of these browsers. As I found, there is a line in the JavaScript's file of the WikiPedia from which the browsers start behaving differently. The line is as follows:

raw = localStorage.getItem(mw.loader.store.getStoreKey());

the value for 'raw' while using Google Chrome is 'null'. But, the value for 'raw' while using 'PhantomJS' is some JavaScript Functions. This difference causes both browsers to behave differently and assign different values to one of the parameters at the end.

I am sure that before executing this line, there is no line for localStorage.setItem() and I am wondering why PhantomJS can load those functions into the 'raw'? Where are these functions coming from? Does PhantomJS have any problem with 'localStorage' command?

the reason for this problem is the fact that PhantomJS, in spite of other browsers like Chrome, does not remove the localStorage file automatically. Therefore, in each run, it uses the previous saved information for a particular website. In order to avoid this problem, we need to remove localStorage file before running PhantomJS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM