1

I had a Windows 8.1 jsproject, now updated to the Universal Windows (UAP/UWP)app.

Previously this function was working, it was calling like

installLocationProxy(window);
installLocationProxy(document);

function installLocationProxy(obj) {
            var descriptor;
            var descriptorProto = obj;
            do {
                descriptor = Object.getOwnPropertyDescriptor(descriptorProto, "location");
                descriptorProto = !descriptor && descriptorProto && Object.getPrototypeOf(descriptorProto);
            } while (descriptor == null);
            if (!descriptor || !descriptor.get || !descriptor.set)
                return;
            var proxy = new LocationProxy(descriptor.get.call(obj));
            Object.defineProperty(obj, "location", {
                "get": function () {
                    return proxy;
                },
                "set": function (location) {
                    if (typeof location === 'string' || location && location instanceof String) {
                        proxy.assign(location, NavigationMethods.Location);
                    }
                    else {
                        return descriptor.set.call(obj, location);
                    }
                }
            });
        }

but now I am getting error "Cannot redefine non-configurable property 'location'" on this line Object.defineProperty(obj, "location".

While googling I found that the now the window.location is readonly and not writable, so cannot be overridden.

For reference it can be checked here https://gist.github.com/zacharytamas/082e538784ebe07e40f9

But I am not sure how to override the window.location property? Can anybody help?

Gopal Devra
  • 564
  • 2
  • 5
  • 24
  • Does this answer your question? [Why can't I redefine a property in a Javascript object?](https://stackoverflow.com/questions/25517989/why-cant-i-redefine-a-property-in-a-javascript-object) – Michael Freidgeim Oct 22 '20 at 22:13

0 Answers0