Skip to content

Commit

Permalink
BDE-240: Inject content script into the page to detect disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
fbematol committed Jan 13, 2025
1 parent 66ed302 commit c943b30
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/main/content-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(async () => {
let connected;

try {
const response = await fetch('/nuxeo/json/cmis');
// Some pages can return an HTML page with 404 message on it.
// We should validate that the response is a json object.
await response.json();
connected = response.ok;
} catch (error) {
connected = false;
}

if (!connected) {
await chrome.runtime.sendMessage({
extension: 'nuxeo-web-extension',
component: 'serverConnector',
action: 'disconnect',
params: []
});
}
})();
11 changes: 10 additions & 1 deletion src/main/manifest-chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,14 @@
},
"default_title": "Nuxeo Dev Tools",
"default_popup": "popup/index.html"
}
},
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"js": ["content-script.js"]
}
]
}
9 changes: 9 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ export default defineConfig(({ mode }) => {
],
hook: 'writeBundle', // run the plugin at the end of bundling
}),
copy({
targets: [
{
src: 'src/main/content-script.js',
dest: `dist/${browserVendor}`,
}
],
// hook: 'writeBundle', // run the plugin at the end of bundling
}),
htmlReparent({ browserVendor, buildEntry, sourceDir: 'src', outputDir: `dist/${browserVendor}` }),
mainReparent({ browserVendor, buildEntry, sourceDir: 'src', outputDir: `dist/${browserVendor}` }),
astPatch({ browserVendor, buildEntry }),
Expand Down

0 comments on commit c943b30

Please sign in to comment.