如何更改 firefox javascript 引擎规则?错误处理
How to change firefox javascript engine rules? Error handling
function hasLiedAboutBrowser()
{
// Assume browser is Firefox but user agent fakes Google Chrome browser
var browser = 'Chrome';
// We create an error to see how it is handled
var errFirefox;
try
{
// eslint-disable-next-line no-throw-literal
throw 'a';
}
catch (err)
{
try
{
console.log('before err.toSource() line'); // This line will work on every browser
err.toSource();
console.log('after err.toSource() line'); // This line will work only on Firefox browser
errFirefox = true; // This line will work only Firefox browser
}
catch (errOfErr)
{
// if err.toSource() throws an exception browser is not a firefox.
errFirefox = false;
}
}
if (errFirefox && browser !== 'Firefox' && browser !== 'Other')
{
console.log("You lied about your browser.");
}
else
{
console.log("All fine");
}
}
hasLiedAboutBrowser();
此代码告诉我们用户何时对浏览器撒谎。
我需要的是 "change firefox javascript error handling rules" 这样 firefox 就会像其他浏览器一样处理错误
我该怎么做?
1-) 从源代码编译 firefox? (如果是这样,规则可能在哪里?)
2-) 更改 omni.ja 存档文件中的一些 javascript 代码? (不太可能)
知道怎么做吗?
Firefox 在 String
上定义了 toSource
,因此只需将其设为未定义即可:
String.prototype.toSource = undefined;
document.getElementsByTagName('button')[0].addEventListener('click', hasLiedAboutBrowser);
document.getElementsByTagName('button')[1].addEventListener('click', function() {
String.prototype.toSource = undefined;
console.log('removed toSource from string prototype');
});
function hasLiedAboutBrowser() {
// Assume browser is Firefox but user agent fakes Google Chrome browser
var browser = 'Chrome';
// We create an error to see how it is handled
var errFirefox;
try {
// eslint-disable-next-line no-throw-literal
throw 'a';
} catch (err) {
try {
console.log('before err.toSource() line'); // This line will work on every browser
err.toSource();
console.log('after err.toSource() line'); // This line will work only on Firefox browser
errFirefox = true; // This line will work only Firefox browser
} catch (errOfErr) {
// if err.toSource() throws an exception browser is not a firefox.
errFirefox = false;
}
}
if (errFirefox && browser !== 'Firefox' && browser !== 'Other') {
console.log("You lied about your browser.");
} else {
console.log("All fine");
}
}
<button>Check Browser</button>
<button>remove toSource</button>
function hasLiedAboutBrowser()
{
// Assume browser is Firefox but user agent fakes Google Chrome browser
var browser = 'Chrome';
// We create an error to see how it is handled
var errFirefox;
try
{
// eslint-disable-next-line no-throw-literal
throw 'a';
}
catch (err)
{
try
{
console.log('before err.toSource() line'); // This line will work on every browser
err.toSource();
console.log('after err.toSource() line'); // This line will work only on Firefox browser
errFirefox = true; // This line will work only Firefox browser
}
catch (errOfErr)
{
// if err.toSource() throws an exception browser is not a firefox.
errFirefox = false;
}
}
if (errFirefox && browser !== 'Firefox' && browser !== 'Other')
{
console.log("You lied about your browser.");
}
else
{
console.log("All fine");
}
}
hasLiedAboutBrowser();
此代码告诉我们用户何时对浏览器撒谎。
我需要的是 "change firefox javascript error handling rules" 这样 firefox 就会像其他浏览器一样处理错误
我该怎么做?
1-) 从源代码编译 firefox? (如果是这样,规则可能在哪里?)
2-) 更改 omni.ja 存档文件中的一些 javascript 代码? (不太可能)
知道怎么做吗?
Firefox 在 String
上定义了 toSource
,因此只需将其设为未定义即可:
String.prototype.toSource = undefined;
document.getElementsByTagName('button')[0].addEventListener('click', hasLiedAboutBrowser);
document.getElementsByTagName('button')[1].addEventListener('click', function() {
String.prototype.toSource = undefined;
console.log('removed toSource from string prototype');
});
function hasLiedAboutBrowser() {
// Assume browser is Firefox but user agent fakes Google Chrome browser
var browser = 'Chrome';
// We create an error to see how it is handled
var errFirefox;
try {
// eslint-disable-next-line no-throw-literal
throw 'a';
} catch (err) {
try {
console.log('before err.toSource() line'); // This line will work on every browser
err.toSource();
console.log('after err.toSource() line'); // This line will work only on Firefox browser
errFirefox = true; // This line will work only Firefox browser
} catch (errOfErr) {
// if err.toSource() throws an exception browser is not a firefox.
errFirefox = false;
}
}
if (errFirefox && browser !== 'Firefox' && browser !== 'Other') {
console.log("You lied about your browser.");
} else {
console.log("All fine");
}
}
<button>Check Browser</button>
<button>remove toSource</button>