Skip to content

Commit

Permalink
Using adoptedStyleSheets in shadow root in Firefox breaks
Browse files Browse the repository at this point in the history
Error message "Accessing from Xray wrapper is not supported."
Switching to injecting styles via innerHTML
  • Loading branch information
stefanw committed Dec 23, 2023
1 parent 46077d7 commit d6923dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/sitebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ class SiteBot implements SiteBotInterface {

loadingArea.parentNode.insertBefore(shadowHost, loadingArea.nextSibling)

const sheet = new CSSStyleSheet()
sheet.replaceSync(STYLES)

this.shadow = shadowHost.attachShadow({ mode: 'closed' })
this.shadow.adoptedStyleSheets = [sheet]
this.shadow.innerHTML = STYLES
this.container = document.createElement('div')
this.shadow.appendChild(this.container)
}
Expand Down
12 changes: 10 additions & 2 deletions src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ export const MESSAGE_ID = 'bibbot-message'
export const BOT_ID = 'bibbot-loader'
export const LOADER_ID = 'bibbot-loading'

export const STYLES = `
export const CSS = `
#${LOADER_ID} {
display: flex;
font-size: 35px;
animation: bibbot-working 2s ease-in-out 0s infinite;
}
Expand Down Expand Up @@ -52,10 +54,16 @@ h2 {
export const LOADER_HTML = `
<div id="${BOT_ID}">
<h2>BibBot</h2>
<img id="${LOADER_ID}" src="${ICON}" alt="BibBot" height="40" width="30" style="width:30px;height:40px">
<div id="${LOADER_ID}">
<img src="${ICON}" alt="BibBot" height="40" width="30" style="width:30px;height:40px">
</div>
<p id="${MESSAGE_ID}">Pressedatenbank wird aufgerufen...</p>
</div>`

export const STYLES = `
<style>${CSS}</style>
`

export const FAILED_HTML = `<strong>Artikel konnte nicht gefunden werden</strong>
<ul style="text-align:left;margin-left:1rem">
<li>Titel können sich von der Druckausgabe unterscheiden. Nutzen Sie das offene Tab um nach Stichworten zu suchen.</li>
Expand Down

0 comments on commit d6923dd

Please sign in to comment.