Skip to content

Commit

Permalink
wkwebview: Update test page
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Mar 25, 2024
1 parent b1983ee commit 21c8171
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions wkwebview/WebView/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
<head>
<title>Page title in index.html</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark">
</head>
<body>
<h1>It works!</h1>
<button onclick="testDownload()">Test file download</button>
<button onclick="testCamera()">Test camera</button>
<button onclick="testMicrophone()">Test microphone</button>
<button onclick="window.close()">window.close()</button>
<button onclick="testLocalFetchFromMain()">Test local fetch from main</button>
<button onclick="testLocalFetchFromBlobWorker()">Test local fetch from blob: worker</button>
<script>
const testDownload = async () => {
const blob = new Blob([
Expand All @@ -20,7 +23,7 @@ <h1>It works!</h1>
});
ExternalDownloadHelper.download("test.txt", blob);
};

const testCamera = async () => {
const stream = await navigator.mediaDevices.getUserMedia({
video: true
Expand All @@ -31,7 +34,7 @@ <h1>It works!</h1>
video.controls = true;
document.body.appendChild(video);
};

const testMicrophone = async () => {
const stream = await navigator.mediaDevices.getUserMedia({
audio: true
Expand All @@ -42,6 +45,41 @@ <h1>It works!</h1>
audio.controls = true;
document.body.appendChild(audio);
};

let testFetchURL = new URL('', location.href).href;

const testLocalFetchFromMain = async () => {
fetch(testFetchURL)
.then(res => res.text())
.catch(err => {
return `${err}`;
})
.then(text => {
const el = document.createElement("pre");
el.textContent = text;
document.body.appendChild(el);
});
};

const testLocalFetchFromBlobWorker = async () => {
const source = `
console.log("Inside worker...");
fetch(${JSON.stringify(testFetchURL)})
.then(res => res.text())
.then(text => postMessage(text))
.catch(err => postMessage('' + err));
`;
const blob = new Blob([source], {
type: 'application/javascript'
});
const url = URL.createObjectURL(blob);
const worker = new Worker(url);
worker.addEventListener('message', (e) => {
const el = document.createElement("pre");
el.textContent = e.data;
document.body.appendChild(el);
});
};
</script>
</body>
</html>

0 comments on commit 21c8171

Please sign in to comment.