You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome扩展ADSkip报Uncaught ReferenceError: click is not defined求助

问题根源

错误直接来自script.js中的未定义函数调用:你代码中后两个setInterval直接调用了click()函数,但全局作用域下没有定义这个同名函数,因此触发ReferenceError。
之前功能正常大概率是你早前代码中封装过该工具函数,后续迭代时误删,或是依赖了访问页面自带的全局click函数,近期对应页面逻辑调整后该函数被移除导致报错。

修复方案

方法1:补充封装click工具函数(推荐,代码复用性更高)

直接在script.js最顶部添加如下代码即可:

// 封装通过类名点击元素的公共函数
function click(className) {
  const targetBtn = document.querySelector(`.${className}`);
  if (targetBtn) targetBtn.click();
}

方法2:修改定时器逻辑,和现有可用逻辑对齐

把后两个setInterval的调用方式改成和第一个跳过广告按钮的逻辑一致,示例如下:

setInterval(() => {
  const overlayCloseBtn = document.getElementsByClassName("ytp-ad-overlay-close-button");
  if(overlayCloseBtn != undefined && overlayCloseBtn.length > 0) {
    overlayCloseBtn[0].click();
  }
}, 300);
console.log("Ads closed");

setInterval(() => {
  const otherCloseBtn = document.getElementsByClassName("avnts-close-btn-con");
  if(otherCloseBtn != undefined && otherCloseBtn.length > 0) {
    otherCloseBtn[0].click();
  }
}, 300);
console.log("Ads closed");

额外提示

Chrome浏览器已经停止对Manifest V2扩展的支持,建议后续迭代时升级为Manifest V3版本,避免扩展无法正常上架、运行。

内容的提问来源于stack exchange,提问作者Shadow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 20:27:00