1

I have created an Edge extension that currently makes an Ajax call to a web API i have also developed in order to request data. Currently after hours of testing, I know the Ajax call works correctly and returns the relevant data.

My issue is the Ajax call will fail when I attempt to call it from my Edge extension. It doesn't provide any reasoning or errors, just simply the error message I added to the Ajax call (error: .... see below). Having tested the exact same extension and Ajax call to my web API in chrome the Ajax call from within the extension works correctly and returns the data from which I can then use.

$(document).ready(function () {
    $select = $('#brandDropdownList');
    $.ajax({
        type: "GET",
        url: 'http://localhost:44358/api/brands',
        dataType: 'JSON',
        success:function(data) {
            $select.html('');
            $.each(data, function(key, val) {
                $select.append('<option id="' + val.brand_id + '">' + val.brand_name + '</option>');
            })
        },
        error: function(){
            $select.html('<option id="-2">Please try again...</option>');
        }
    });  

Why is this? I have no errors or issues, it works fine in Chrome, but not in Edge and unfortunately I have to use Edge for the project I am undertaking. The only error I can see in the console in dev tools is that there is a warning for:

"serviceWorker.getRegistrations is rejected due to unsecure context or host restriction in ms-browser-extension"

TylerH
  • 19,065
  • 49
  • 65
  • 86
  • Hi, welcome to stackoverflow. Could you please provide the code you are using to perform your AJAX? Also, even if the error might not tell much, it would be appreciated if you pasted a copy of what it says here. In doubt, please refer to the [ask] section – Nicolas Jan 09 '20 at 19:30
  • Does Edge let you do xhr's from localhost? – Calculuswhiz Jan 09 '20 at 20:41
  • Is there a way in which I could get around this then? –  Jan 09 '20 at 21:09

1 Answers1

1

It might because Microsoft Edge has network isolation by default for security reasons. You could enable loopback and debug the localhost server by running the following command from a cmd prompt as administrator, then restart Microsoft Edge:

CheckNetIsolation LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbwe

Reference:

(1) Failed to fetch error with MS Edge Extension

(2) Why does Microsoft Edge open some local websites...

(3) How to debug localhost on Microsoft Edge

Yu Zhou
  • 6,874
  • 1
  • 4
  • 20