[英]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.