Closed Bug 1411873 Opened 7 years ago Closed 7 years ago

"An unexpected error occurred" when requesting optional permission (origin)

Categories

(WebExtensions :: Untriaged, defect)

57 Branch
defect
Not set
normal

Tracking

(firefox57 wontfix)

RESOLVED DUPLICATE of bug 1382953
Tracking Status
firefox57 --- wontfix

People

(Reporter: kotykserg, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36

Steps to reproduce:

Prerequirements:
- Firefox Developer Edition 57.0b11 (64-bit) (see screenshot)
- Have An extension with options page with the script (see attachement youtube-downloader-firefox/data/options.js)
- Go to settings and click save.


Actual results:

- see error in console "Error: An unexpected error occurred"
- permissions.origins has not changed


Expected results:

- There should be no error
- "<all_urls>" should be added as one of origins
Basically the code that is falling (not to download all source):
```

const permissionsToRequest = {
    origins: ["<all_urls>"]
}

function requestPermissions() {

    function onResponse(response) {
        if (response) {
            console.log("Permission was granted");
        } else {
            console.log("Permission was refused");
        }
        return browser.permissions.getAll();
    }

    browser.permissions.request(permissionsToRequest)
        .then(onResponse)
        .then((currentPermissions) => {
            console.log(`Current permissions:`, currentPermissions);
        });
}

function saveOptions(e) {
    requestPermissions();
    e.preventDefault();
}

document.addEventListener("DOMContentLoaded", initOptionEvents);

```
Forget to add a single line of code, should look like this:
```
const permissionsToRequest = {
    origins: ["<all_urls>"]
}

function requestPermissions() {

    function onResponse(response) {
        if (response) {
            console.log("Permission was granted");
        } else {
            console.log("Permission was refused");
        }
        return browser.permissions.getAll();
    }

    browser.permissions.request(permissionsToRequest)
        .then(onResponse)
        .then((currentPermissions) => {
            console.log(`Current permissions:`, currentPermissions);
        });
}

function saveOptions(e) {
    requestPermissions();
    e.preventDefault();
}

document.querySelector("#settings").addEventListener("submit", saveOptions);
```

(In reply to Serhii from comment #1)
> Basically the code that is falling (not to download all source):
> ```
> 
> const permissionsToRequest = {
>     origins: ["<all_urls>"]
> }
> 
> function requestPermissions() {
> 
>     function onResponse(response) {
>         if (response) {
>             console.log("Permission was granted");
>         } else {
>             console.log("Permission was refused");
>         }
>         return browser.permissions.getAll();
>     }
> 
>     browser.permissions.request(permissionsToRequest)
>         .then(onResponse)
>         .then((currentPermissions) => {
>             console.log(`Current permissions:`, currentPermissions);
>         });
> }
> 
> function saveOptions(e) {
>     requestPermissions();
>     e.preventDefault();
> }
> 
> document.addEventListener("DOMContentLoaded", initOptionEvents);
> 
> ```
Component: Untriaged → WebExtensions: Untriaged
Product: Firefox → Toolkit
Flags: needinfo?(aswan)
Summary: WebExtension "An unexpected error occurred" when requesting optional permission (origin) → "An unexpected error occurred" when requesting optional permission (origin)
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Flags: needinfo?(aswan)
Resolution: --- → DUPLICATE
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: