Shahar Kazaz Shahar Kazaz - 29 days ago 11
Javascript Question

Object.defineProperty not working on window object IE11

I'm trying to change the value for window.navigator.onLine using Object.defineProperty.

The command I ran is :

Object.defineProperty(window.navigator, "onLine", {value: false, configurable: true});


which worked on :

* Edge 13

* Opera 40.0

* Chrome 54.0

* FireFox 49.0

Any ideas why this didn't work? it says that IE11 is suppose to support this method.

Answer

From the spec it sounds like window.navigator.onLine is a readonly. i.e. if you can't override it by setting the value directly, you might be doing bad things.

If you're doing this to test some behaviour, perhaps you'd be better of mocking the navigator object rather than trying to change a readonly property. (Sorry if that's a bad assumption, feel free to give some more context :).)

Comments