Created
June 23, 2021 08:23
-
-
Save cawa-93/4c1793bf1df43f041872af870decb5a9 to your computer and use it in GitHub Desktop.
Reproducion for Electron issue #29319
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | |
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | |
<title>Electron Issue #29319</title> | |
</head> | |
<body> | |
<ol> | |
<li>Open browser developer tools</li> | |
<li>Go to <b>Application</b> -> <b>Storage</b> </li> | |
<li>Enable <b>"Simulate custom storage quota"</b>. 1MB for example.</li> | |
<li>Push the data in the IndexedDB below several times to Exceeded quota</li> | |
<li>Expected Behavior: Alert with <code>QuotaExceededError</code> | |
</ol> | |
<form> | |
<label>How many Items push to IndexedDB? | |
<input type="number" value="10000"> | |
<button>Push data to IndexedDB</button> | |
</label> | |
</form> | |
<p id="storage-stat"> | |
Storage quota: <span id="quota"></span>.<br> | |
Storage usage: <span id="usage"></span> (<span id="usage-percent"></span>%) | |
</p> | |
<!-- You can also require other files to run in this process --> | |
<script src="./renderer.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modules to control application life and create native browser window | |
const {app, BrowserWindow} = require('electron') | |
const path = require('path') | |
function createWindow () { | |
// Create the browser window. | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
}) | |
// and load the index.html of the app. | |
mainWindow.loadFile('index.html') | |
// Open the DevTools. | |
// mainWindow.webContents.openDevTools() | |
} | |
// This method will be called when Electron has finished | |
// initialization and is ready to create browser windows. | |
// Some APIs can only be used after this event occurs. | |
app.whenReady().then(() => { | |
createWindow() | |
app.on('activate', function () { | |
// On macOS it's common to re-create a window in the app when the | |
// dock icon is clicked and there are no other windows open. | |
if (BrowserWindow.getAllWindows().length === 0) createWindow() | |
}) | |
}) | |
// Quit when all windows are closed, except on macOS. There, it's common | |
// for applications and their menu bar to stay active until the user quits | |
// explicitly with Cmd + Q. | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') app.quit() | |
}) | |
// In this file you can include the rest of your app's specific main process | |
// code. You can also put them in separate files and require them here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateStorestat() { | |
return navigator.storage.estimate().then(estimate => { | |
console.log({estimate}) | |
document.body.querySelector('#quota').textContent = estimate.quota | |
document.body.querySelector('#usage').textContent = estimate.usage | |
document.body.querySelector('#usage-percent').textContent = estimate.usage * 100 / estimate.quota | |
}) | |
} | |
updateStorestat() | |
document.querySelector('form').addEventListener('submit', async (event) => { | |
event.preventDefault() | |
pushDataToIdb(document.querySelector('input').valueAsNumber) | |
.then(updateStorestat) | |
.catch(e => alert(e)) | |
}) | |
function pushDataToIdb(arraySize = 10000) { | |
const dataPlacehonder = new Array(arraySize).fill('text-data-placeholder') | |
return new Promise((resolve, reject) => { | |
const request = window.indexedDB.open("MyTestDatabase", 1); | |
request.onerror = event => reject(event.target.error) | |
request.onupgradeneeded = function(event) { | |
var db = event.target.result; | |
db.createObjectStore("test-data", { keyPath: "index", autoIncrement: true }); | |
}; | |
request.onsuccess = function(event) { | |
db = event.target.result; | |
db.onerror = event => reject(event.target.error) | |
var transaction = db.transaction(["test-data"], "readwrite"); | |
transaction.onerror = event => reject(event.target.error) | |
transaction.onabort = event => reject(event.target.error) | |
transaction.oncomplete = () => resolve() | |
var objectStore = transaction.objectStore("test-data"); | |
var request = objectStore.add(dataPlacehonder); | |
request.onerror = event => reject(event.target.error) | |
}; | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Empty */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment