简体   繁体   English

我在Chrome 77上的网站无法加载任何数据,但在Chrome 76上可以正常运行

[英]My website on Chrome 77 doesn't load any data, but it works fine on Chrome 76

What's worse, is that my tests pass using Chrome 77 with Chromedriver 77 (the tests pass, the data is loaded in the webpages, etc.). 更糟糕的是,我使用Chrome 77和Chromedriver 77通过了测试(测试通过了,数据已加载到网页中,等等)。 It's only if I manually pull up a Chrome 77 browser and test it that it fails. 只有当我手动启动Chrome 77浏览器并对其进行测试时,它才会失败。

Here's basically what my code is doing: 这基本上是我的代码正在做的事情:

// Get the query parameter "operation" from the URL
let match = new RegExp("[?&]operation=([^&]*)").exec(window.location.search);
let param = match && decodeURIComponent(match[1].replace(/\+/g, " "));

// Sanitize the URL from XSS Injection
let param = param ? window.DOMPurify.sanitize(param) : param;

if(param === "View") {
    // Load data from the server
}

The problem is that in Chrome 77 param === "View" is false! 问题是在Chrome 77 param === "View"是错误的! But it's not false when using Chrome 77 on it's own. 但是单独使用Chrome 77并非没有错。

I figured it out! 我想到了! The problem is the Chrome 77 turns on the TrustedTypes API by default. 问题是Chrome 77默认情况下会启用TrustedTypes API。 But it's turned off if Chrome 77 is started through Chromedriver, which is a pretty nasty bug . 但是,如果通过Chromedriver启动Chrome 77,则会关闭该功能,这是一个非常讨厌的错误

The fix to get Chrome 77 / Chromedriver 77 to fail like it does when you manually hit the page is to enable this chrome feature: 使Chrome 77 / Chromedriver 77像手动单击页面时一样失败的解决方法是启用此chrome功能:

--enable-blink-features=TrustedDOMTypes

You'd put it in the same place you see --no-sandbox or --disable-infobars . 您将其放在--no-sandbox--disable-infobars

Great! 大! Now your tests fail as they should. 现在,您的测试会按预期失败。 Next, to fix the error, change this line: 接下来,要修复错误,请更改此行:

// Sanitize the URL from XSS Injection
let param = param ? window.DOMPurify.sanitize(param) : param;

To this instead: 为此:

// Sanitize the URL from XSS Injection
let param = param ? (window.DOMPurify.sanitize(param) || "").toString() : param;

The toString() is the most important part. toString()是最重要的部分。 A TrustedType object is being returned now, instead of a String. 现在将返回TrustedType对象,而不是String。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 网站可以在Opera中正常运行,但不能在Chrome中正常运行 - Website works fine in Opera, but not in Chrome 网站在Firefox中无法正常运行,但在Chrome中无法正常运行 - Website works fine in firefox but not in Chrome CSS无法在Firefox,IE,Edge中加载,但在Chrome中可以正常运行 - CSS won't load in Firefox, IE, Edge, but works fine in Chrome 页面在chrome / firefox中工作正常,但在IE中不起作用 - Page works fine in chrome/firefox but doesn't in IE 在img对象中使用Draggable在Chrome中无法正常工作 - Using draggable in an img object doesn't works fine in Chrome Jquery.addClass() function 在 chrome 中不起作用,但在 Mozilla 中可以正常工作 - Jquery .addClass() function doesn't work in chrome but it works fine in Mozilla iFrame 在 Chrome 中不起作用(在 FF、IE 和 Safari 中工作正常) - iFrame doesn't work in Chrome (works fine in FF, IE and Safari) 页面在 Firefox 中无法正常工作,但在 chrome 中工作正常 - Page doesn't work as intended in Firefox but works fine in chrome 网站在chrome上可以正常运行,但在mozilla或IE上不能正常运行 - Website works fine on chrome but not on mozilla or IE 为什么我的代码无法在chrome中工作? 它适用于Internet Explorer - Why doesn't my code work in chrome? It works in internet explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM