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

Safari扩展中getComputedStyle/getPropertyValue返回异常值求助

Safari扩展中获取-webkit-user-select属性返回空的解决办法

你遇到的问题是Safari对CSS前缀属性在getComputedStyle中的处理特性导致的:在Safari里,通过getPropertyValue('-webkit-user-select')无法直接获取到值,因为浏览器会将带前缀的-webkit-user-select映射为标准属性user-select,直接查询标准属性就能拿到正确的计算值。

具体修改方案

把判断逻辑调整为优先检查标准属性user-select,或者直接访问计算样式对象的驼峰式属性userSelect,两种方式都能在Safari中正确获取到值:

修改后的函数示例:

function anyIllegalElements(selection) {
  return !!selectedElements(selection).filter(el => {
    const computedStyle = window.getComputedStyle(el);
    // 直接用标准属性或驼峰式属性
    return computedStyle.getPropertyValue('user-select') === 'none' ||
           computedStyle.userSelect === 'none' ||
           el.tagName === 'IFRAME';
  }).length;
}

补充说明

Safari的getComputedStyle会自动归一化CSS属性,将厂商前缀的属性值同步到对应的标准属性上,所以无需再单独查询带-webkit-前缀的版本。如果需要兼容更早版本的Safari,可以同时保留两种检查,但实际测试中,标准属性的查询已经能覆盖绝大多数场景。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 06:52:35