使用 web-inspector 检测用户是否更改了某些内容

Detect if user changes something with web-inspector

有什么方法可以检测用户是否使用 web-inspector 进行了任何更改? 例如,用户打开检查器并更改 div 中的文本以伪造它。有什么方法可以检测到吗?

刷新页面以查看网站上的原始内容,因为网络检查员所做的更改未存储在服务器上。

如果您只有几个要观看的元素,请使用 MutationObserver

mozilla 文档中的示例用法:

// Select the node that will be observed for mutations
var targetNode = document.getElementById('some-id');

// Options for the observer (which mutations to observe)
var config = { attributes: true, childList: true };

// Callback function to execute when mutations are observed
var callback = function(mutationsList) {
    for(var mutation of mutationsList) {
        if (mutation.type == 'childList') {
            console.log('A child node has been added or removed.');
        }
        else if (mutation.type == 'attributes') {
            console.log('The ' + mutation.attributeName + ' attribute was modified.');
        }
    }
};

// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(targetNode, config);

// Later, you can stop observing
observer.disconnect();