我正在撰写Google Chrome扩展程序。我知道Chrome目前在localStorage
的最大允许大小上设置了5MB的限制。但是我很好奇是否有任何方法可以从Chrome本身获得这个,就像JS常量/全局变量一样?
PS。我只是讨厌对这个值进行硬编码以防将来更改它。
答案 0 :(得分:0)
We assume that one character equals one byte, but this is not a safe assumption. Strings in JavaScript are UTF-16, so each character requires two bytes of memory. This means that while many browsers have a 5 MB limit, you can only store 2.5 M characters.
很难预测域的剩余数量,即使它被设置为5 MB。
阅读了关于HTML5存储的内容。很有可能寻找无限存储选项。
https://developers.google.com/chrome/whitepapers/storage#unlimited
在本文档中,他们建议使用清单:
"storage": {
"managed_schema": "schema.json"
},
我没有测试过自己,但值得尝试一下。
如果有效,请告诉我。
谢谢。答案 1 :(得分:0)
2021 年更新: https://developer.chrome.com/docs/extensions/reference/storage/#property-local
使用for (let i = 1; i <= 14; i++) {
let a = i;
let nthTerm = a - 1;
let b = 1 / 2;
let quadraticSequence = b * a ** 2 + b * a;
console.log(`${nthTerm} ${quadraticSequence}`);
const num = 93;
// use quadratic sequence to count up to a number <= 93;
for (i = 0; i <= num; i++quadraticSequence) {
console.log(i);
}
}
。