electron/spec/fixtures/api/shared-dictionary/main.js
trop[bot] 9a7848ced1
feat: Add shared dictionary management APIs (#44950)
* Add bare-bones GetSharedDictionaryUsageInfo

* Add GetSharedDictionaryInfo()

* Improve API, use isolation keys

* Add documentation

* Update docs/api/session.md



* Update shell/browser/api/electron_api_session.cc



* Add tests

* Implement feedback <3

* Improve tests

* chore: lint

* docs: add note about clearing cache in ses.clearData

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Felix Rieseberg <fr@makenotion.com>
2024-12-04 13:35:08 -08:00

42 lines
1.7 KiB
JavaScript

const { app, BrowserWindow, session } = require('electron');
const path = require('node:path');
app.setPath('userData', path.join(__dirname, 'user-data-dir'));
// Grab the command to run from process.argv
const command = process.argv[2];
app.whenReady().then(async () => {
const bw = new BrowserWindow({ show: true });
await bw.loadURL('https://compression-dictionary-transport-threejs-demo.glitch.me/demo.html?r=151');
// Wait a second for glitch to load, it sometimes takes a while
// if the glitch app is booting up (did-finish-load will fire too soon)
await new Promise(resolve => setTimeout(resolve, 1000));
try {
let result;
const isolationKey = {
frameOrigin: 'https://compression-dictionary-transport-threejs-demo.glitch.me',
topFrameSite: 'https://compression-dictionary-transport-threejs-demo.glitch.me'
};
if (command === 'getSharedDictionaryInfo') {
result = await session.defaultSession.getSharedDictionaryInfo(isolationKey);
} else if (command === 'getSharedDictionaryUsageInfo') {
result = await session.defaultSession.getSharedDictionaryUsageInfo();
} else if (command === 'clearSharedDictionaryCache') {
await session.defaultSession.clearSharedDictionaryCache();
result = await session.defaultSession.getSharedDictionaryUsageInfo();
} else if (command === 'clearSharedDictionaryCacheForIsolationKey') {
await session.defaultSession.clearSharedDictionaryCacheForIsolationKey(isolationKey);
result = await session.defaultSession.getSharedDictionaryUsageInfo();
}
console.log(JSON.stringify(result));
} catch (e) {
console.log('error', e);
} finally {
app.quit();
}
});