I did some tests. Let me add some information to everyone.
trusted context: extension origin (extension page or service worker)
untrusted context: content script (main world)
1. AccessLevel is only related to chrome.storage.session in MV3, not related to local/sync/managed.
2. setAccessLevel() method can only be run on storage.session in trusted context.
By default, AccessLevel is "TRUSTED_CONTEXTS":
- In extension pages: all session/local/sync/managed are available.
- In content script: local/sync/managed are available, but session is not available.
In trusted context, change AccessLevel to "TRUSTED_AND_UNTRUSTED_CONTEXTS":
chrome.storage.session.setAccessLevel({accessLevel: "TRUSTED_AND_UNTRUSTED_CONTEXTS"});
PS: local/sync/managed don't have setAccessLevel() method.
Now, AccessLevel is "TRUSTED_AND_UNTRUSTED_CONTEXTS":
- In extension pages: all session/local/sync/managed are available.
- In content script: session is also available now.