繁体   English   中英

phantomJS是否支持地理定位?

[英]Does phantomJS support geolocations?

我正在尝试用PhantomJS运行qunit测试用例。 当phantomJS尝试访问DOM的navigator.geolocation函数时,我的一个测试就悬而未决。 相同的测试在浏览器中正常工作,只需使用phantomJS挂在控制台中。

doe phantomJS支持地理位置? 有什么建议吗?

如果条件,则在以下中断

  if(navigator.geolocation) {
            window.navigator.geolocation.watchPosition(updateLocation, null, { frequency: 3000 });
        }

没有。

只需查看features.js示例。

>phantomjs.exe features.js
Detected features (using Modernizr 2.0.6):

Supported:
  touch
  generatedcontent
  fontface
  flexbox
  canvas
  canvastext
  postmessage
  websqldatabase
  hashchange
  history
  draganddrop
  websockets
  rgba
  hsla
  multiplebgs
  backgroundsize
  borderimage
  borderradius
  boxshadow
  textshadow
  opacity
  cssanimations
  csscolumns
  cssgradients
  cssreflections
  csstransforms
  csstransitions
  localstorage
  sessionstorage
  webworkers
  applicationcache
  svg
  inlinesvg
  smil
  svgclippaths

Not supported:
  csstransforms3d
  webgl
  geolocation
  indexeddb
  video
  audio

您可以通过在初始化时将所需的函数注入DOM来添加“geolocation-fake-support”来运行测试或执行其他操作。 以下示例伪造了navigator.geolocation.getCurrentPosition,因此当浏览器中的网站调用此API端点时,PhantomJS将始终返回已配置的位置。

webpage.onInitialized = function() {
    webpage.injectJs('geolocation.js')
};

geolocation.js:

window.navigator.geolocation = {
    getCurrentPosition: function (success, failure) {
        success({
            coords: {
                // Will always return Germany, Rostock
                latitude: 54.0834,
                longitude: 12.1004

            }, timestamp: Date.now()
        });
    }
};

暂无
暂无

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

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