Created
October 22, 2022 18:46
-
-
Save fregante/d87ffc87dc648a790d5d85a7cda72a67 to your computer and use it in GitHub Desktop.
Request permissions from devtool panel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8" /> | |
<script src="devtools_page.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.devtools.panels.create("New demo panel", "", "panel.html"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"version": "0.0.0", | |
"name": "Devtools demo", | |
"description": "Devtools", | |
"optional_permissions": ["*://*/*"], | |
"devtools_page": "devtools_page.html" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8" /> | |
<button>Request</button> | |
<script src="panel.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.querySelector("button").addEventListener("click", async () => { | |
try { | |
await chrome.permissions.request({ | |
origins: ["https://example.com/*"], | |
}); | |
} catch (error) { | |
document.body.append( | |
document.createElement("hr"), | |
error.name, | |
": ", | |
error.message | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment