OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
657 stars 93 forks source link

Fetch API throw a "Load failed" error #4511

Open niquenen opened 1 month ago

niquenen commented 1 month ago

Your Environment

Expected behavior

Fetch text (or JSON) data and print the result with console.log.

Current behavior

When using the Fetch API, an error is thrown with the following message: "Load Failed", from a TypeError object.

Steps to reproduce

  1. Open Excel.
  2. Open Automate tab.
  3. Create a new script.
  4. Paste the following code.

    async function main(workbook: ExcelScript.Workbook): Promise<void>
    {
       try {
           await fetch('https://google.com');
       }
       catch (error) {
           console.log(error);
       }
    }

Another example:

async function main(workbook: ExcelScript.Workbook): Promise<void>
{
    try {
        // TypeError
        await fetch('https://example.com');
    }
    catch (error) {
        console.log(error);
    }
    try {
        // TypeError
        await fetch('https://google.com');
    }
    catch (error) {
        console.log(error);
    }
    try {
        // TypeError
        await fetch('https://github.com');
    }
    catch (error) {
        console.log(error);
    }
    try {
        await fetch('https://api.github.com');
    }
    catch (error) {
        console.log(error);
    }
}

Link to live example(s)

None

Provide additional details

None

Context

Perform HTTP request to retrieve data. Base on an example from the documentation:

Are there any restrictions on domains? Example with the GitHub API and NOAA(https://www.noaa.gov) works, but example.com or Google failed.

Useful logs

Screenshot 2024-05-28 at 17 51 22 Screenshot 2024-05-30 at 10 42 23
microsoft-github-policy-service[bot] commented 1 month ago

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

shanshanzheng-dev commented 1 month ago

Hi @niquenen We'll be looking into this problem, thanks for reporting! we will report back here if we have a suggestion for you.

niquenen commented 1 month ago

I try on Windows and a stack trace is displayed in the log.

Screenshot of Excel with a code editor
shanshanzheng-dev commented 3 weeks ago

Hi @niquenen Thanks for the detailed information. We have created a bug <#9029924> to triage this issue. Thanks.