OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
681 stars 95 forks source link

localStorage in Mac doesn't share the data between Word, Excel and PowerPoint add-ins #3159

Open repl-minatee-p opened 1 year ago

repl-minatee-p commented 1 year ago

I have defined the Word, Excel and PowerPoint add-ins in one manifest.xml file. I am using localStorage to share data between these Word, Excel and PowerPoint add-ins. It works fine in Windows but not in Mac. In Mac, the data are shared between the same app add-ins but not across the apps add-ins. For example, if I store data in the localStorage of word add-in then it gets shared with all other word add-ins but not with excel and powerpoint add-ins.

Your Environment

Expected behavior

I expect localStorage.getItem(key) in Excel and PowerPoint add-ins should get the value set in Word add-in using localStorage.setItem(key, value) and vice versa. It works fine in Windows but not in Mac.

Current behavior

Word add-in localStorage data are not shared with Excel and PowerPoint add-ins and vice versa.

Context

My add-in customers need data to be shared between Word, Excel and PowerPoint add-ins.

ghost commented 1 year ago

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

penglongzhaochina commented 1 year ago

Hi @jargil could you please take a look this issue?

alexuaua commented 1 year ago

Hello @penglongzhaochina ! I am encountering the same issue. I was going to open a new issue, but found that this one already addresses the same problem. Could you please update me if there are any updates on this matter? Thank you!

Steps to Reproduce:

It appears that Office apps might isolate add-ins per application (and do not utilize GroupContainers unlike some other features). This particular distinction from Windows is not documented, and it would be really great if Mac apps allow an add-in to share localStorage/indexedDB across different hosts, given that the add-in ID and origin remain consistent, as we are using the same manifest.xml.

macabacus-sd commented 1 year ago

@msftbot @penglongzhaochina I have the same issue on Excel for Mac. The problem does not occur for me on Windows.

penglongzhaochina commented 1 year ago

Hi all,

Could you please check whether the local storage key which the add-in want to get are really there? If the local storage key really are there you can paste the error message which the API can't get the local storage content to here. It would be very helpful,Thanks!

alexuaua commented 12 months ago

Hi @penglongzhaochina,

No, when I check the storage key in a different host application, it is not present (for example, a key set in Excel does not appear when checked in Word). There is no error message; in both applications, localStorage (as well as other browser APIs like indexedDB) functions correctly, but they operate independently, unlike on Windows.

penglongzhaochina commented 12 months ago

Can below link give you some insights? This issue may be similar with your scenario. Could you please go through this link to check whether your issue is related with this issue. having a workaround there.

https://github.com/OfficeDev/office-js-docs-pr/issues/4249

macabacus-as commented 12 months ago

@penglongzhaochina, thanks, but the issue discussed in the issue you provided a link for is about the Dialog API and online platform (and thus the storage partitioning applies). The issue reported by @repl-minatee-p (we also observe) only relates to the Office for Mac - Office for Windows apps do not separate storage for the same add-in running in different apps.

penglongzhaochina commented 11 months ago

Hi all,

This is a by-design behavior on mac.

alexuaua commented 11 months ago

Hi @penglongzhaochina,

1) Is the behavior observed on Windows hosts indicative of a bug? I am uncertain as to why there is a need for separate storage when the add-in is identical. However, if this is a security-related issue, I would appreciate guidance on whether to report this as a problem for the Windows application and as a documentation issue. Specifically, the section titled 'Persist add-in state and settings' suggests that localStorage can be utilized to maintain the state of the add-in.

2) Additionally, there is OfficeRuntime.Storage interface. The documentation indicates that this should be accessible across different hosts (and even different add-ins from the same domain), with a storage limit of 10 MB per domain, potentially shared by multiple add-ins. According to the documentation, this interface is expected to provide consistent values for an add-in from the same domain. However, on Mac, this is not the case.

penglongzhaochina commented 11 months ago

Hi @jargil ,

could you please help explain this issue?

alexuaua commented 11 months ago

I just found this issue seems to be related: https://github.com/OfficeDev/office-js/issues/2928 (and covers OfficeRuntime.Storage).