Select to view content in your preferred language

[esri.core.workers] Failed to create Worker. JSON Parse failing on 'applicationURL'

1555
7
Jump to solution
11-03-2022 03:35 PM
ConnerFarrant
Emerging Contributor
Trying to initialize a map and map view, works fine in a sample project (localhost:4200/). But when using it with real environment URL (http://localhost:4200/portal/dashboard?elementPath=\\ThisIsAServer\SomeString\Name\Site\HJSU&query=1...), the workers fail to create with error; 

 

Uncaught SyntaxError: Bad escaped character in JSON at position 97', filename: 'blob:http://localhost:4201/c708361e-0008-48a9-95b9-c955556554e8'

 

I have debugged this error to being the applicationURL in the config JSON that the worker tries to parse which has a single and double \ in the (original) URL. The config is trying to escape the \ which results in '\\\\' and '\\' respectively, but as this is JSON inside JS, it requires 8 slashed instead of 4 to parse. See the attached fiddle with the current code and the working code. 

 
Question is how to fix this as I can't edit the worker code? and cannot parse the applicationURL through with my own escaping? 
 
@arcgis/core - Latest (4.24) 
Angular 13.2
0 Kudos
1 Solution

Accepted Solutions
René_Ténière
Frequent Contributor

I narrowed it down to JSON.parse() not liking the double backslash \\.

When the user opens a url: http://localhost:5173/?locale=fr&config=assets\config\config.json what gets input into the applicationURL of esriConfig is http://localhost:5173/?locale=fr&config=assets\\config\\config.json. My workaround is to use the following url: http://localhost:5173/?locale=fr&config=assets%5cconfig%5cconfig.json however, it is less user-readable and depends on user validation.

Is it possible for you to modify your code to encodeURI(window.location.href) as the value you put into applicationURL so this exception will not happen in most case-scenarios?

View solution in original post

0 Kudos
7 Replies
AndyGup
Esri Regular Contributor

Hi @ConnerFarrant  are you building a custom ArcGIS JS API app or using an ArcGIS Dashboard? If you are using a Dashboard, you'll need to follow that product's System Requirements and Tech Support procedures. Here's a link to the ArcGIS Dashboard community site if you need to reach out to them for more guidance.

0 Kudos
ConnerFarrant
Emerging Contributor

This is a JS App, simply trying to display a map on the page and dynamically pass through the lat, long etc. This issue is caused by the URL string. 

0 Kudos
AndyGup
Esri Regular Contributor

If it's a custom JS app we will need a link to a simple github repo, codesandbox or stackblitz.com sample. If you need a basic Angular + ArcGIS JS API sample as a starting point, we recommend using this one: https://github.com/Esri/jsapi-resources/tree/master/esm-samples/jsapi-angular-cli.

0 Kudos
René_Ténière
Frequent Contributor

I have this same issue. It does not correctly parse the = character because if I replace the value with %3d in the URL it will work fine. Has anyone looked into this issue? Does esriConfig require the full URL in applicationURL or can it take the URL before the querystring?

0 Kudos
René_Ténière
Frequent Contributor

Here are more details with exception code attached:

Ren_Tnire_0-1701446021386.png

 

 

 

0 Kudos
René_Ténière
Frequent Contributor

I narrowed it down to JSON.parse() not liking the double backslash \\.

When the user opens a url: http://localhost:5173/?locale=fr&config=assets\config\config.json what gets input into the applicationURL of esriConfig is http://localhost:5173/?locale=fr&config=assets\\config\\config.json. My workaround is to use the following url: http://localhost:5173/?locale=fr&config=assets%5cconfig%5cconfig.json however, it is less user-readable and depends on user validation.

Is it possible for you to modify your code to encodeURI(window.location.href) as the value you put into applicationURL so this exception will not happen in most case-scenarios?

0 Kudos
ConnerFarrant
Emerging Contributor

Quite old question but yes, that was essentially the solution (can't remember exactly). I seem to have created a wrapper component to hold the ArcGIS map which handled all the encoding and parsing as I could not do it directly with the ArcGIS map due to the JSON parsing issue. Hopefully this helps you out too. 

0 Kudos