Skip to content

Tabs (toggleSections) does not work if localStorage is unavailable #3323

@echeung-amzn

Description

@echeung-amzn

Describe the bug

  1. Deploy Dokka-generated docs to some platform that renders docs within a sandboxed iframe.
  2. Navigate to some page that has tabs, such as a class that has Types, Constructors, Functions, and Parameters.
  3. Try to navigate to another tab such as Constructors.
  4. Does not switch to tab due to sandboxing preventing the usage of localStorage.

Example stack trace from browser console:

Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.
    at toggleSections (https://[redacted]/dokka/scripts/platform-content-handler.js:251:5)
    at toggleSectionsEventHandler (https://[redacted]/dokka/scripts/platform-content-handler.js:270:5)
    at HTMLDivElement.<anonymous> (https://[redacted]/dokka/scripts/platform-content-handler.js:161:58)
toggleSections @ platform-content-handler.js:251
toggleSectionsEventHandler @ platform-content-handler.js:270
(anonymous) @ platform-content-handler.js:161

Expected behaviour
Other tab is shown even if localStorage is unavailable.

Screenshots
N/A

To Reproduce

<iframe
  src="https://[redacted]/dokka/index.html" 
  sandbox="allow-modals allow-popups allow-scripts allow-top-navigation-by-user-activation allow-downloads">

Dokka configuration
Configuration of dokka used to reproduce the bug

register<DokkaTask>("dokka") {
    outputDirectory.set(file("[redacted]/dokka"))
    dokkaSourceSets.configureEach {
        externalDocumentationLink {
            noJdkLink.set(true)
            noStdlibLink.set(true)
            noAndroidSdkLink.set(true)
            url.set(URL("[redacted]"))
            packageListUrl.set(URL("file:///[redacted]"))
        }
    }
}

Installation

  • Operating system: Linux
  • Build tool: Gradle v7.6.1
  • Dokka version: 1.6.21

Additional context
I understand that the use of localStorage was added in #921 to persist the tab state across page navigations. However, it'd seem appropriate to silently fail and still allow tabs to be shown even if localStorage cannot be used, at the expense of a lack of persistence.

Are you willing to provide a PR?
I could try taking a stab at it.

Metadata

Metadata

Assignees

Labels

bugformat: htmlAn issue/PR related to Dokka's default HTML output formathtml: frontendAn issue/PR that only or primarily requires frontend work (html/css)tech-debtA technical issue that is not observable by the users, but improves maintainers quality of life

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions