Error “Cannot redefine non-configurable property 'location'” on window.location in javascript using in Universal Windows app (UAP/UWP)

Gopal Devra 6 Reputation points

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


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)  
            var proxy = new LocationProxy(;  
            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, 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 it cannot be overridden.

For reference, it can be checked here

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

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 26,391 Reputation points Microsoft Employee


    Welcome to Microsoft Q&A!

    So you are trying to intercept and redirect the navigation, right?

    If it's your own site, you just call a JS function, do your logic in it and assign the new URL to the windows.location.

    But if it's not your site, it belongs to others, we don't recommend you to do this because of security issues.