thefack
V2EX  ›  问与答

爱奇艺 PC 网页端 播放广告时,是怎么检测到我把它放到了后台的?

  •  
  •   thefack · Nov 8, 2020 · 1463 views
    This topic created in 2037 days ago, the information mentioned may be changed or developed.

    环境是 Windows10 20h2,用的 Chrome 86,已经暂停了广告拦截器扩展

    当网页不可见时,广告倒计时就停止减 1 了(虽然声音表示广告暂时还在继续,但是播放几秒后就不继续播放广告了,切回去,视频区域为黑屏状态)

    然后我用扩展想屏蔽对网页可见性的检测,但是没有效果。请问还有什么原因吗?

    扩展的的主要代码:

    !function () {
      // 需在 网页 js 环境中运行的代码
      let code = function () {
        // visibilityState 、hidden 状态
        Object.defineProperty(document, 'visibilityState', {
          configurable: false,
          writable: false,
          value: 'visible',
        });
    
        Object.defineProperty(document, 'hidden', {
          configurable: false,
          writable: false,
          value: false,
        });
    
    	// 拦截检测可行性的事件
        for (let eventName of ["visibilitychange", "webkitvisibilitychange"]) {
          window.addEventListener(eventName, function handle(e) {
            e.stopImmediatePropagation();
            e.preventDefault();
          }, true);
        }
      };
    
      // 嵌入 js 代码
      let script = document.createElement('script');
      script.textContent = '(' + code + ')()';
      (document.head || document.documentElement).appendChild(script);
      script.remove();
    }();
    
    greed1is9good
        1
    greed1is9good  
       Nov 8, 2020 via Android
    不用后台,失去焦点就停了吧
    hfJ433
        2
    hfJ433  
       Nov 8, 2020
    芒果视频点击暂停视频就会自动变成广告画面,恶心的不行。
    ysc3839
        3
    ysc3839  
       Nov 8, 2020
    onblur?
    happylty
        4
    happylty  
       Nov 8, 2020
    焦点检测
    thefack
        5
    thefack  
    OP
       Nov 9, 2020
    @greed1is9good
    @hfJ433
    @ysc3839
    @happylty
    谢谢大家,我扩展的问题,已解决
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1080 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 23:21 · PVG 07:21 · LAX 16:21 · JFK 19:21
    ♥ Do have faith in what you're doing.