Skip to content

Commit 2a0a426

Browse files
committed
fix: add clipboard fallback for insecure contexts
- Add document.execCommand('copy') fallback when navigator.clipboard.writeText() fails (e.g. HTTP sites) - Verified via agent-browser E2E: session creation, page refresh, session persistence, bridge connect/disconnect all work
1 parent 30131ef commit 2a0a426

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

server/static/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,18 @@
271271
$("expiry").textContent = "Expires in " + min + ":" + rem;
272272
}
273273
function copyText(id, button, label) {
274-
navigator.clipboard.writeText($(id).textContent).catch(function () {});
274+
var text = $(id).textContent;
275+
navigator.clipboard.writeText(text).catch(function () {
276+
// Fallback for older browsers / insecure contexts
277+
var ta = document.createElement("textarea");
278+
ta.value = text;
279+
ta.style.position = "fixed";
280+
ta.style.opacity = "0";
281+
document.body.appendChild(ta);
282+
ta.select();
283+
document.execCommand("copy");
284+
document.body.removeChild(ta);
285+
});
275286
var old = button.textContent;
276287
button.textContent = label;
277288
button.disabled = true;

0 commit comments

Comments
 (0)