Search code examples
office-jsoffice-addinsexcel-addinscustom-functions-excel

Cookie is not shared between taskpane and custom functions in Excel on the web


I am having problem sharing cookie between the custom functions and the taskpane when deploying my Excel add-in to the web. I followed this guide to share runtime and cookie between taskpane and custom function. I tested in offline Excel (in both Mac and Window) and it works fine. However, when I sideload the function on the web, the taskpane is loaded as an iframe inside the web, thus the taskpane and custom functions have different runtime and cookie. There is no error message, they just don't share the run time any more, which messes up my custom function which uses cookie entered by user from the taskpane to validate them.

My target audience is not people using Excel on the web but it is a part of the verification process to publish the add-in to Appsource so I need to find a way to make it works on the web as well. Appreciate any help.


Solution

  • This issue was caused by a new security feature of web browser. The third-party cookie was blocked by the feature, so that iframe cannot read the cookies. You can try this to resolve it:

    For Edge/Chrome, add settings of SameSite=None and Secure to the cookie, e.g.

    document.cookie="...your cookie;SameSite=None; Secure"
    

    For Safari, refer to this document: Develop your Office Add-in to work with ITP when using third-party cookies

    In addition, Web Storage API works well with shared runtime in Excel online. If you're using cookies for purposes other than authentication, then consider using localStorage for your scenario.

    Thanks,

    Rundong