【发布时间】:2012-07-15 14:45:00
【问题描述】:
我需要扩展 Audio 对象以提供停止功能。通常这段代码可以工作:
Audio.prototype.stop = function() {
this.pause();
this.currentTime = 0;
}
但是,我需要在 Chrome 扩展程序的内容脚本中执行此操作,并且由于上下文是分开的,因此更改不会传播到其他上下文。
我曾尝试使用 this unsafeWindow hack 尝试突破隔离环境,但没有成功,并尝试使用 Object.create 并设置 constructor 属性。
【问题讨论】:
-
内容脚本永远无法访问页面的全局
window对象。问题与Building a Chrome Extension - Inject code in a page using a Content script 重复。旁注,我会使用if (!Audio.prototype.stop) ...;,以避免在实现stop时发生冲突。
标签: javascript google-chrome-extension html5-video html5-audio