fix(frontend): clipboard polyfill for HTTP (non-secure) contexts — copy buttons threw writeText-of-undefined on nodes
CI / check (push) Failing after 6m9s
CI / check (push) Failing after 6m9s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,26 @@ import { router } from './router'
|
||||
import App from './App.vue'
|
||||
import './style.css'
|
||||
|
||||
// Clipboard polyfill: on nodes the app is served over plain HTTP (non-secure
|
||||
// context), where navigator.clipboard does not exist — every copy button would
|
||||
// throw "Cannot read properties of undefined (reading 'writeText')".
|
||||
if (!navigator.clipboard) {
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
value: {
|
||||
async writeText(text: string) {
|
||||
const ta = document.createElement('textarea')
|
||||
ta.value = text
|
||||
ta.style.cssText = 'position:fixed;opacity:0'
|
||||
document.body.appendChild(ta)
|
||||
ta.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(ta)
|
||||
},
|
||||
async readText() { return '' },
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(router)
|
||||
app.mount('#app')
|
||||
|
||||
Reference in New Issue
Block a user