![](/img/trans.png)
[英]Deployment on Vercel fails because cannot convert undefined or null to object
[英]SetimeOut interval fails with “Cannot convert undefined or null to object”
我正在使用tampermonkey進入用戶腳本,無法解決此錯誤,任何幫助將不勝感激。
我檢測到鍵很好,空格鍵觸發此功能,只要鍵保持在向下位置,它就會重復。 控制台或多或少地正常寫入輸出30秒,然后出現TypeError。
根據聲譽限制,這是一個截圖:
用戶腳本:
// ==UserScript==
// @name TEST STUFF--------------------
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @run-at document-start
// @include http://*
// @include https://*
// @grant none
// ==/UserScript==
( function()
{
'use strict';
window.addEventListener ( "keydown", CaptureKeyPress );
window.addEventListener ( "keyup", CaptureKeyPress );
var Hotkeys =
{
perform: 32
};
var HotkeyToggle = false;
function CaptureKeyPress ( a )
{
if ( a.keyCode == Hotkeys.perform )
{
a.preventDefault();
a.stopPropagation();
a.cancelBubble = true;
a.stopImmediatePropagation();
if ( a.type == "keydown" && !HotkeyToggle )
{
console.clear();
HotkeyToggle = true;
perform();
}
if ( a.type == "keyup" && HotkeyToggle )
{
HotkeyToggle = false;
}
}
}
function perform()
{
if(HotkeyToggle == false) // exit
{
return 0
}
//do stuff...
console.info("working...");
if(HotkeyToggle == true) // continue after everything completes
{
setTimeout(() => {
perform()
}, 280);
return 0
}
return 1
}
} ) ();
這是Chrome中已確認的錯誤:
另一個看起來有用的解決方案是將函數.bind
到window
,例如:
window.clearTimeout = window.clearTimeout.bind(window);
window.clearInterval = window.clearInterval.bind(window);
window.setTimeout = window.setTimeout.bind(window);
window.setInterval = window.setInterval.bind(window);
該錯誤應該在Chrome 75中修復。
我使用Tampermonkey和谷歌瀏覽器時遇到了同樣的問題。 對我window.setTimeout
是使用window.setTimeout
而不是setTimeout
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.