Fix UUID generation in browsers without crypto.randomUUID
This commit is contained in:
1 parent
b312a50d37
commit
9dd425f765
5 files changed
+172
No files matched your search
@@ -0,0 +1,45 @@
|
||||
window.addEventListener('load', async () => {
|
||||
const wait = async check => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
if (await check()) return;
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
}
|
||||
throw new Error('Timed out: ' + check);
|
||||
};
|
||||
const api = '/_/api/v1/extension/organizer.tasks/items';
|
||||
try {
|
||||
if (!window.uuidNativeWasMissing) throw new Error('Missing native UUID fixture was not applied');
|
||||
if (typeof crypto.randomUUID !== 'function') throw new Error('UUID fallback not loaded');
|
||||
document.getElementById('tasks-new').click();
|
||||
const dialog = document.getElementById('tasks-dialog');
|
||||
await wait(() => dialog.open && dialog.querySelector('[name=title]'));
|
||||
const title = dialog.querySelector('[name=title]');
|
||||
title.value = 'HTTP compatibility project';
|
||||
title.dispatchEvent(new Event('input', {bubbles:true}));
|
||||
document.getElementById('tasks-form').requestSubmit();
|
||||
await wait(() => !dialog.open);
|
||||
const response = await fetch(api + '?kind=project');
|
||||
if (!response.ok) throw new Error('Project query failed');
|
||||
const project = (await response.json()).items.find(item => item.title === title.value);
|
||||
if (!project || !/^[0-9a-f-]{14}4[0-9a-f-]{21}$/.test(project.uuid)) throw new Error('Project not saved with UUID v4');
|
||||
if (!document.getElementById('tasks-list').textContent.includes(project.title)) throw new Error('Saved project not listed');
|
||||
|
||||
const frame = document.createElement('iframe');
|
||||
frame.src = '/v/plan/project/' + project.uuid;
|
||||
document.body.append(frame);
|
||||
await wait(() => frame.contentDocument?.getElementById('tasks-quick-title') && frame.contentDocument.readyState === 'complete');
|
||||
const doc = frame.contentDocument;
|
||||
if (!frame.contentWindow.uuidNativeWasMissing) throw new Error('Task fallback fixture was not applied');
|
||||
doc.getElementById('tasks-quick-title').value = 'HTTP compatibility task';
|
||||
doc.getElementById('tasks-capture').requestSubmit();
|
||||
await wait(() => Array.from(doc.querySelectorAll('[name=title]')).some(input => input.value === 'HTTP compatibility task'));
|
||||
const tasks = await fetch(api + '?project=' + project.uuid).then(r => r.json());
|
||||
if (!tasks.items.some(item => item.title === 'HTTP compatibility task' && item.project_uuid === project.uuid)) throw new Error('Task not saved in project');
|
||||
document.body.dataset.vimReady = '1';
|
||||
} catch (error) {
|
||||
const output = document.createElement('pre');
|
||||
output.id = 'error';
|
||||
output.textContent = error.stack || error.message;
|
||||
document.body.append(output);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user