要怎麼去檢查某一個網頁的事件是人為去觸發,還是透過 javascript / jquery 觸發?
答案是檢查 event.which
event.which
will be undefined
if the event is triggered with code.
線上範例:https://jsfiddle.net/VYHmt/
javascript 範例:
$('body').click(function(event) {
$(this).append('<div>' + event.which + '</div>');
}).click();
實際測試,在 jsfiddle 右下的 console 裡輸入 $("body").trigger("click");
就可以看到 undefined
資料來源:
- https://stackoverflow.com/questions/5948350/determine-whether-a-given-javascript-action-has-been-initiated-by-user
- https://stackoverflow.com/questions/6982072/click-source-in-javascript-and-jquery-human-or-automated
要怎麼讓 chrome extension 裡的 javascript/jquery 的 click 可以比照真人去點擊?
https://stackoverflow.max-everyday.com/2024/10/chrome-extension-javascript-click-with-event-which/