首页 > 解决方案 > 我在 Facebook 登录页面中收到“未捕获(承诺)类型错误:无法重新定义属性:cookie”js 错误。有人可以帮忙吗?

问题描述

我在 Facebook 登录页面中收到“未捕获(承诺)类型错误:无法重新定义属性:cookie”js 错误。有人可以帮忙吗?我找不到导致错误的原因,但是当我从 js 文件中删除以下代码时,错误消失了。

这是我初始化facebook jdk的代码,

function statusChangeCallback(response) {

    if (response.status === 'connected') {   // Logged into your webpage and Facebook.
        var fbAccessToken = response.authResponse.accessToken;
        console.log("statuscallback: " + fbAccessToken);
        verify_user(fbAccessToken, "facebook");
    } else {
        
    }
}

function checkFBLoginState() {
    FB.getLoginStatus(function (response) {
        statusChangeCallback(response);
    });
}


window.fbAsyncInit = function () {
    //FB JavaScript SDK configuration and setup
    FB.init({
        appId: '***MYAPPID***',
        cookie: true, 
        xfbml: true,  
        version: 'v10.0' 
    });
    FB.getLoginStatus(function (response) {   // Called after the JS SDK has been initialized.
        statusChangeCallback(response);        // Returns the login status.
    });
};

(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) { return; }
    js = d.createElement(s); js.id = id;
    js.src = "https://connect.facebook.net/tr_TR/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function fbLogout() {
    FB.logout(function (response) {
        // Person is now logged out
    });
}

这是我在控制台上遇到的错误:

Uncaught (in promise) TypeError: Cannot redefine property: cookie
    at Function.defineProperty (<anonymous>)
    at defineProperty (<anonymous>:814:17)
    at blockCookies (<anonymous>:1235:6)
    at init$7 (<anonymous>:1326:10)
    at <anonymous>:923:14
    at Array.forEach (<anonymous>)
    at Object.initProtections (<anonymous>:921:26)

这是引发错误的以下代码:

// TODO make rollup aware of this so it can tree shake
    const mozProxies = 'wrappedJSObject' in window;

    function defineProperty (object, propertyName, descriptor) {
        if (mozProxies) {
            const usedObj = object.wrappedJSObject;
            const UsedObjectInterface = window.wrappedJSObject.Object;
            const definedDescriptor = new UsedObjectInterface();
            ['configurable', 'enumerable', 'value', 'writable'].forEach((propertyName) => {
                // TODO check if value is complex and export it if so.
                if (propertyName in descriptor) {
                    definedDescriptor[propertyName] = descriptor[propertyName];
                }
            });
            ['get', 'set'].forEach((methodName) => {
                if (methodName in descriptor) {
                    exportFunction(descriptor[methodName], definedDescriptor, { defineAs: methodName });
                }
            });
            UsedObjectInterface.defineProperty(usedObj, propertyName, definedDescriptor);
        } else {//error thrown
            Object.defineProperty(object, propertyName, descriptor);
        }
    }

标签: javascriptfacebook

解决方案


推荐阅读