guyujiezi / cicada

基于谷雨解字的Chrome浏览器插件
MIT License
119 stars 7 forks source link

Uncaught TypeError: MutationObserver is not a constructor #3

Open XieJiSS opened 5 years ago

XieJiSS commented 5 years ago
// plugin.js@line 50
  let observer = new MutationObserver((mutations, observer) => {
// ...
guyujiezi commented 5 years ago

Which version of the Chrome are you using?

XieJiSS commented 5 years ago

v73 I believe this is the latest stable version

Edit: Not all webpages can trigger this error. I'll inform you as soon as I understand how to reproduce it.

guyujiezi commented 5 years ago

It's surprising that everything works fine on my system with chrome73. I'll try to reproduce this bug

XieJiSS commented 5 years ago

I caught it.

You can reproduce it by searching for any text in Baidu. Or if you're lucky enough, visiting www.baiu.com without doing anything can trigger the bug. A piece of code in https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/js/all_async_search_e86b5ac.js always sets MutationObserver to null:

try{window.MutationObserver=window.WebKitMutationObserver=window.MozMutationObserver=null}catch(e){}

Now, this seems not to be a bug of cicada itself, but since Baidu is widely used in Chinese Internet, maybe it's a good idea to pack a polyfill of MutationObserver inside cicada to support it. The minified version is around 3KB in size.

Full js file (with ext .txt) is here: all_async_search_e86b5ac.js.txt

guyujiezi commented 5 years ago

damn baidu. It's a tricky problem...

guyujiezi commented 5 years ago

image image

I repaired this bug. But it does not work all the time