tjx666 / awesome-chrome-extension-boilerplate

Use react + typescript + webpack to enhance your chrome extension development experience
MIT License
405 stars 45 forks source link

ts 内popup 如何与background通信呢? #12

Closed yugonglian closed 1 year ago

yugonglian commented 4 years ago

在popup 定义 var back= chrome.extension.getBackGroundPage(); 调用background 的方法出错了,找不到方法 back.test();

tjx666 commented 4 years ago

通过 window.test = function() {} 在 background 中定义 test 方法应该就没问题了

yugonglian commented 3 years ago

通过 window.test = function() {} 在 background 中定义 test 方法应该就没问题了

不行,var back= chrome.extension.getBackGroundPage() back 返回的就是一个window 对象,但是在background 并不能直接用window 对象

tjx666 commented 1 year ago

推荐使用 https://github.com/zikaari/webext-bridge#readme