Search code examples
node.jscorsoffice-jsmicrosoft-edgeoffice-addins

Launch Excel via NPM and sideload Add-In using Edge with CORs - Debug Office App


I want to disable CORs for the Edge browser runtime so I can develop app without having to configure the backend(s) to accept localhost as a CORs domain.

Note: The production URL will be configured w/ CORs whitelist, but as I'm developing on localhost I'm getting CORs errors that localhost isn't accepted by backend. This is a pre-flight check that should be disableable from the localhost.

There are options for both Edge and Chrome to do this, but as Excel is launching the browser for me "somehow", I don't know how I can add CLI flags to the browser launch process.

Here is how I currently start the debugging in VSCode.

{
  "tasks": [
    {
      "label": "Debug: Excel Desktop",
      "type": "npm",
      "script": "start:desktop -- --app excel",
      "presentation": {
        "clear": true,
        "panel": "dedicated"
      },
      "problemMatcher": []
    },
    {
      "label": "Stop Debug",
      "type": "npm",
      "script": "stop",
      "presentation": {
        "clear": true,
        "panel": "shared",
        "showReuseMessage": false
      },
      "problemMatcher": []
    }
  ]
}

See https://github.com/OfficeDev/Office-Addin-Scripts/issues/806


Solution

  • You can basically add flags to the Webview2 browser process by setting the following environment variable as so:

    setx WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS --disable-web-security
    

    Note: I had to reboot for it to take effect