CORS conflict for plugin during preview (loading a local file in JS via URI)

0 favourites
  • 7 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • I am integrating the face-api.js into C3 as a plugin, but I am having an issue with preview. It works fine with the export of game to HMTL5 and hosted (locally or on a remote server.) It also works fine when exported with Electron and run as a desktop app (https://electronforconstruct.armaldio.xyz/).

    The issue occurs when the JS api requests a file via a fetch URI (that's included in the root of the plugin and the root of the exported HTML5.) The error on the Chrome console is:

    Access to fetch at 'https://editor.construct.net/r151/preview/ssd_mobilenetv1_model-weights_manifest.json'
    from origin 'https://preview.construct.net' has been blocked by CORS policy:
     No 'Access-Control-Allow-Origin' header is present on the requested resource.
    If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch
     the resource with CORS disabled.
    

    However, preview fails any suggestions? Is it possible to enable CORS between preview.construct.net and editor.construct.net or is that a security issue for construct.net?

  • Project files are local, and not hosted on any server, so you can't fetch them in preview mode. Make all requests through AssetManager and everything will work.

  • Thanks Ashley, I will take a look at the AssetManger SDK.

  • Ashley

    I'm trying to use the AssetManager, but I still get a CORS error during preview.

    Did I read your below message incorrectly? Does fetching not work at all during preview and AssetManager does not help for fetching during preview?

    I have this in my events (and j.json project file in the project.)

    + System: On start of layout
    -> Run JavaScript: var loadedJson = c3_runtimeInterface._GetLocalRuntime()._assetManager.FetchJson("j.son")
    console.log(loadedJson)
    

    The above fails with a CORS error during preview.

    Thanks for the help.

  • Ah, learning slowly but surely, this works in preview:

    async function go() {
    	var projUrl = ''
    	projUrl = await c3_runtimeInterface._GetLocalRuntime()._assetManager.LoadProjectFileUrl('j.json')
    	var loadedJson = {}
    	loadedJson = await	c3_runtimeInterface._GetLocalRuntime()._assetManager.FetchJson(projUrl)
    console.log(loadedJson)
    }
    go()
    
  • It looks like you have a typo in the filename.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • By the way you're also using undocumented unsupported features in that code, so I can't offer any further help if it's not working.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)