为什么不能在Chrome扩展程序中创建自定义元素? [英] Why can't you create Custom Elements in Chrome Extensions?

查看:161
本文介绍了为什么不能在Chrome扩展程序中创建自定义元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Chrome扩展程序中创建自定义元素,但customeElements.definenull.

I attempted to create a custom element in a Chrome extension but customeElements.define is null.

customElements.define('customElement', class extends HTMLElement {
    constructor() {
        super();
    }
    ...
});

因此,显然Chrome浏览器不希望扩展程序创建自定义元素.但为什么?有安全隐患吗?

So apparently Chrome doesn't want extensions to create custom elements. But why? Is it a security risk?

我似乎无法在Chrome扩展指南中找到任何不允许的内容.

I can't seem to find anything in Chrome's extension guide that says it's not allowed.

推荐答案

您可能需要先检查此文章,以充分了解自定义元素的作用以及如何构建它们.如前所述,在构建自定义元素时,您还需要检查document.registerElement是否可用.否则,您只需加载webcomponents.js即可对其进行填充.

You may want to first check this article to fully understand what custom elements do and how to build them. As discussed, in building a custom element, you also need to check if document.registerElement is available. Otherwise, you can simply load webcomponents.js to polyfill it.

这里是您可能需要检查其他洞察力的其他参考.

Here are additional references that you may want to check for additional insights.

  • Custom Elements v1: Reusable Web Components. Rules on creating custom elements are enumerated here.
  • Registering a custom element from a chrome extension. This requires the usage of the webcomponentsjs polyfill. Chrome will prevent native registerElement from being executed within a chrome extension.

这篇关于为什么不能在Chrome扩展程序中创建自定义元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆