After the localStorage operation in the iframe is completed, the data cannot be synchronized to the same page opened in the tab

2,551 views
Skip to first unread message

bolin liao

unread,
Jul 16, 2023, 10:24:44 PM7/16/23
to Chromium Extensions
Hello,

I load the  `tpass.xxx.gov.cn`  page through iframe under the `17dz.com` , and then set localStorage in `tpass.xxx.gov.cn`, it working.

when i open the  `tpass.xxx.gov.cn` in new tab, the localStorage is empty.   it,s mean that localStorage set in iframe can not share?

企业微信截图_596774e9-64e1-4ef7-96c4-8b947504b4bb.png

it should be has data in localStorage, but nothing

企业微信截图_f00bc8ac-5456-48e7-801e-a5987b6a48b6.png

I want to know why?

Thanks!

wOxxOm

unread,
Jul 17, 2023, 12:44:12 AM7/17/23
to Chromium Extensions, bolin liao
Judging by the screenshots (note the appended 17dz.com) this is caused by storage partitioning.

wOxxOm

unread,
Jul 17, 2023, 12:52:07 AM7/17/23
to Chromium Extensions, wOxxOm, bolin liao
Assuming it's your extension that adds the iframe, a possible solution per the documentation requires two things: 1) do it inside an intermediate web_accessible_resources iframe and 2) add tpass.xxx.gov.cn to host_permissions in manifest.json, so the final hierarchy will be "top site" -> web_accessible_resources iframe -> tpass.xxx.gov.cn.

Jackie Han

unread,
Jul 17, 2023, 1:46:16 AM7/17/23
to wOxxOm, Chromium Extensions, bolin liao
This question and your early question are related to whether localStorage data is shared between top-level frame and iframe.

Chrome is introducing a new feature: Storage Partitioning. It is rolling out since Chrome 115 but not yet available in all stable versions.
You can test it by enabling chrome://flags/#third-party-storage-partitioning

1. In old mode (not partitioning storage)
iframes in different websites and itself as a top-level website are shared data in localStorage.

2. In new mode (partitioning storage)
a) for regular websites
localStorage data are not shared. They are different storage instances.
For example, iframe(c.com) in a.com, iframe(c.com) in b.com and top-level frame(c.com) are not shared data.

b) for extension pages
there are two cases:
- a website embed an extension page as an iframe
- an extension page embed a website page as an iframe

That article says:
If the extension has host_permissions for the iframe origin, then the iframe will be treated as the top-level frame and not the extension page. If an extension embeds an iframe with an extension URL into a top-level site with host permissions, the iframe will be treated as first-party with the extension rather than partitioned by the top-level site.

That means sharing or not sharing data (partitioning or not partitioning storage) depends on whether the extension has the website's host permission.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/be4526c0-7484-4e37-8807-060913944923n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages