admin管理员组文章数量:1182738
I have a configurable option where one option requires an extra permission (scripting) and I'm trying to prompt the user to add it on selecting the configuration option.
The function chrome.permission.request
needs to be called during a user gesture. This SO answer shows how to do it in response to a button click, but I'm having trouble adapting it the solution to this specific context.
I've tried launching it directly from the select form on change like so:
<select
bind:value={$config.search_handler}
onchange={() => {
console.log('onchange');
chrome.permissions.request(
{
permissions: ['scripting']
},
(granted) => {
if (granted) {
console.log('granted');
} else {
console.log('not granted');
}
}
);
}}
>
<option value={SearchTool.SidePanel}>
Search/Manage stacks via sidepanel</option
>
<option class="overlay_select" value={SearchTool.Overlay}>
Search/Manage stacks via overlay</option
>
however, the onchange
code never seems to be called ( log statement never appears, nor do the granted/notgranted statements).
I've tried calling it from within the script section of the component
<script lang="ts">
...
document
.getElementById('search_tool_config')
?.addEventListener('change', () => {
if ($config.search_handler === SearchTool.Overlay) {
chrome.permissions.request({ permissions: ['scripting'] }, (result) => {
if (result) {
console.log('Permission granted');
} else {
console.error('Permission not granted');
}
});
}
});
</script>
This also never Prompts me and the messages never get logged
I've tried adding the event listener in index.ts
where the svelte component is mounted, the code is almost the same as above, and also doesn't seem to work.
So how can I request permissions in a way that will register, while using a select form or some way of indicating mutually exclusive selections?
Full code is here
本文标签: google chrome extensionHow to request permission from a select form optionStack Overflow
版权声明:本文标题:google chrome extension - How to request permission from a select form option - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738288279a2073047.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论