mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
More improvements to the google-ima shim script (#3908)
We have enabled the google-ima shim script again in the DuckDuckGo Privacy Essentials browser extension, and found a couple more issues: - Some websites set the enablePreloading[1] option, which should cause[2] the AdsManager.init() method to trigger the LOADED AdEvent to fire. If the event doesn't fire, those websites can get stuck waiting for the event forever. - When AdsManager.start() method is called, a bunch of events are dispatched in order, to simulate ads loading, playing and finishing. There was a mistake in that logic though. The CONTENT_PAUSE_REQUESTED and CONTENT_RESUME_REQUESTED events[3] should fire as the ads start and finish respectively. By firing the latter early, and skipping the former, some websites got confused and tried to display ad overlays at the same time as playing their content, or didn't display they content at all. 1 - https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/reference/js/google.ima.AdsRenderingSettings#enablePreloading 2 - https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/preload#timing 3 - https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/reference/js/google.ima.AdEvent
This commit is contained in:
parent
8df6c3243c
commit
c1d8f5908d
1 changed files with 14 additions and 3 deletions
|
@ -13,6 +13,8 @@
|
|||
* - Added missing event dispatcher functionality
|
||||
* - Corrected return type of `Ad.getUniversalAdIds()`
|
||||
* - Corrected typo in `UniversalAdIdInfo.getAdIdValue()` method name
|
||||
* - Corrected dispatch of LOAD event when preloading is enabled
|
||||
* - Corrected dispatch of CONTENT_PAUSE/RESUME_REQUESTED events
|
||||
*
|
||||
* Related issue:
|
||||
* - https://github.com/uBlockOrigin/uBlock-issues/issues/2158
|
||||
|
@ -412,6 +414,7 @@ if (!window.google || !window.google.ima || !window.google.ima.VERSION) {
|
|||
constructor() {
|
||||
super();
|
||||
this.volume = 1;
|
||||
this._enablePreloading = false;
|
||||
}
|
||||
collapse() {}
|
||||
configureAdsManager() {}
|
||||
|
@ -437,7 +440,11 @@ if (!window.google || !window.google.ima || !window.google.ima.VERSION) {
|
|||
getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
init(/*w, h, m, e*/) {}
|
||||
init(/*w, h, m, e*/) {
|
||||
if (this._enablePreloading) {
|
||||
this._dispatch(new ima.AdEvent(AdEvent.Type.LOADED));
|
||||
}
|
||||
}
|
||||
isCustomClickTrackingUsed() {
|
||||
return false;
|
||||
}
|
||||
|
@ -457,13 +464,14 @@ if (!window.google || !window.google.ima || !window.google.ima.VERSION) {
|
|||
for (const type of [
|
||||
AdEvent.Type.LOADED,
|
||||
AdEvent.Type.STARTED,
|
||||
AdEvent.Type.CONTENT_RESUME_REQUESTED,
|
||||
AdEvent.Type.CONTENT_PAUSE_REQUESTED,
|
||||
AdEvent.Type.AD_BUFFERING,
|
||||
AdEvent.Type.FIRST_QUARTILE,
|
||||
AdEvent.Type.MIDPOINT,
|
||||
AdEvent.Type.THIRD_QUARTILE,
|
||||
AdEvent.Type.COMPLETE,
|
||||
AdEvent.Type.ALL_ADS_COMPLETED,
|
||||
AdEvent.Type.CONTENT_RESUME_REQUESTED,
|
||||
]) {
|
||||
try {
|
||||
this._dispatch(new ima.AdEvent(type));
|
||||
|
@ -743,7 +751,10 @@ if (!window.google || !window.google.ima || !window.google.ima.VERSION) {
|
|||
constructor(type) {
|
||||
this.type = type;
|
||||
}
|
||||
getAdsManager() {
|
||||
getAdsManager(c, settings) {
|
||||
if (settings && settings.enablePreloading) {
|
||||
manager._enablePreloading = true;
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
getUserRequestContext() {
|
||||
|
|
Loading…
Reference in a new issue