简体   繁体   English

localStorage.getItem()在不同的浏览器中给出不同的结果

[英]localStorage.getItem() gives a different result in different browsers

I am working with PhantomJS. 我正在使用PhantomJS。 I want to compare the behavior of PhantomJS with Google Chrome while loading the first page of WikiPedia. 我想在加载WikiPedia的第一页时比较PhantomJS与Google Chrome的行为。 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. 正如我发现的那样,WikiPedia的JavaScript文件中存在一行,浏览器从中开始表现不同。 The line is as follows: 该行如下:

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

the value for 'raw' while using Google Chrome is 'null'. 使用Google Chrome浏览器时,“原始”的值为“空”。 But, the value for 'raw' while using 'PhantomJS' is some JavaScript Functions. 但是,使用“ PhantomJS”时“ raw”的值是一些JavaScript函数。 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'? 我确定在执行此行之前,localStorage.setItem()没有任何行,我想知道为什么PhantomJS可以将这些函数加载到“原始”文件中? Where are these functions coming from? 这些功能从哪里来? Does PhantomJS have any problem with 'localStorage' command? PhantomJS的'localStorage'命令是否有问题?

the reason for this problem is the fact that PhantomJS, in spite of other browsers like Chrome, does not remove the localStorage file automatically. 造成此问题的原因是,尽管有其他浏览器(例如Chrome),PhantomJS仍不会自动删除localStorage文件。 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. 为了避免此问题,我们需要在运行PhantomJS之前删除localStorage文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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