'File reference in Chrome extension

I would like to load a model in contentScript.js using url './model/model.json'

const MODEL_URL = './model/model.json';
const model = tf.loadLayersModel(MODEL_URL);

but keep getting Request to model/model.json failed with status code 404. Please verify this URL points to the model JSON of the model to load. Could not figure out what went wrong. I also tried '../model/model.json', 'model/model.json', './model/model' et. al..

├── build
│   ├── icons
│   │   ├── ...
│   ├── model
│   │   ├──model.json
│   ├── contentScript.js

Update:

Added "web_accessible_resources": [ "models/*" ] to manifest.json, still get 404.



Solution 1:[1]

use getURL():

tf.loadLayersModel(chrome.runtime.getURL(MODEL_URL));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daolin