浏览器矛盾:一旦选项卡关闭,如何清除SessionStorage,但仍可以从历史记录中恢复?

发布于 2025-02-04 21:28:39 字数 996 浏览 3 评论 0 原文

摘自官方文档:,它说:

页面会话持续到“选项卡或浏览器打开”,并且 在页面重新加载和还原上生存。

在新标签中打开页面 或窗口创建一个具有顶级值的新会话 浏览上下文,这与会话cookie的工作方式不同。

打开 具有相同URL的多个标签/窗口为SessionStorage创建 每个选项卡/窗口。

复制一个选项卡副本副本的sessionstorage 进入新标签。

关闭选项卡/窗口结束会话并清除 sessionstorage中的对象。

没有明显的矛盾吗?

关闭选项卡/窗口结束会话并清除SessionStorage中的对象。

同时,

页面会话持续使用,只要打开选项卡或浏览器打开,并且可以通过页面重新加载和还原存活。

我已经使用我的网站测试,该网站将访问令牌存储在SessionStorage中。关闭标签后,我可以从历史记录中还原页面,而无需再次登录。

但是这怎么可能是对的? 当我关闭选项卡时,会话结束并清除会话速度中的对象。

但是,当我从历史记录中恢复时,SessionStorage又回来了???

问题:

  1. 这不是显而易见的矛盾吗?这怎么可能是对的?

  2. 关闭选项卡时如何删除SessionStorage对象?它是完整的删除还是仍然保存在某个地方?导致下一个问题:

  3. 恢复页面并恢复sessionstorage时,数据从哪里恢复?

  4. 是否有时间限制无法再还原关闭页面/选项卡?

From the official Doc: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage, it states:

A page session lasts as long as the tab or the browser is open, and
survives over page reloads and restores.

Opening a page in a new tab
or window creates a new session with the value of the top-level
browsing context, which differs from how session cookies work.

Opening
multiple tabs/windows with the same URL creates sessionStorage for
each tab/window.

Duplicating a tab copies the tab's sessionStorage
into the new tab.

Closing a tab/window ends the session and clears
objects in sessionStorage.

Isn't there an obvious contradiction?

Closing a tab/window ends the session and clears objects in sessionStorage.

in the meantime,

A page session lasts as long as the tab or the browser is open, and survives over page reloads and restores.

I have tested with my website, which stores access tokens in sessionStorage. After I close the tab, I can restore the page from history and I do not need to sign in again.

But how can this be right?
When I close the tab, the session is ended and objects in sessionStorage are cleared.

But when I restore from history, the sessionStorage is back again???

Questions:

  1. Isn't this an obvious contradiction? How can this be right??

  2. How does it delete the sessionStorage object when closing the tab? Is it a complete deletion or still saved somewhere? which leads to the next question:

  3. When the page is restored and sessionStorage is restored, where is the data restored from?

  4. Is there a time limit over which one can no longer restore a closed page/tab?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文