简体   繁体   English

内容脚本样式表泄漏到页面中

[英]Content Scripts stylesheet leaks into the page

I am working on an extension.我正在做一个扩展。 The user double clicks on some term on the page and gets the data via a side panel popup.用户双击页面上的某个术语并通过侧面板弹出窗口获取数据。
The data I get is formatted and stored inside a div called innerDiv with class inner-div which is the child of div that is appended into the body.我得到的数据被格式化并存储在一个名为innerDiv的div中,类inner-div是附加到主体中的div的子级。
The js part works fine but the css of that page overwrites my css and also, the extension stylesheet leaks into the page. js 部分工作正常,但该页面的 css 覆盖了我的 css,并且扩展样式表泄漏到页面中。 It goes both ways.它是双向的。

.inner-div{
  position: relative;
  overflow-y: auto;
  color: wheat;
  height: 90%;
  width: 100%;
  text-align: justify;
  font-size: 16px;
}

.inner-div p, h1, h2 , h3, article{
  margin-bottom: 10px;
  color: wheat;
  text-decoration: none;
  border: none;
}

As you can see I've kept my CSS as specific as possible.正如你所看到的,我尽可能保持我的 CSS 特定。 So, there is not way that the page having dom with different classes inherit my css.因此,具有不同类的 dom 页面无法继承我的 css。

Picture of css leaking into page css漏进页面的图片

在此处输入图片说明

Picture of dom element and the class dom元素和类的图片

在此处输入图片说明

I cannot figure out why the extension css is leaking into the page.我无法弄清楚为什么扩展 css 会泄漏到页面中。 Please help!请帮忙!

EDIT :编辑 :

Changed the div name to be more specific extension-inner-div according to the suggestions.根据建议将 div 名称更改为更具体的 extension-inner-div。 The problem persists.问题仍然存在。

在此处输入图片说明

Manifest.json:清单.json:

{
    "manifest_version" : 2,

    "name" : "QWiki",
    "description" : "", 
    "version" : "1.0",

    "browser_action" : {
      "default_popup" : "Wiki_Viewer.html",
      "default_title" : "QWiki"
    },

    "content_scripts" : [{
      "css": ["inject.css"],
      "matches": ["http://*/*" , "https://*/*"],
      "js" : ["jquery.min.js" , "inject.js"]
    }],

    "permissions" : [
      "activeTab",
      "https://en.wikipedia.org/*"
    ]
}   

Just to bump Beslinda N's comment , I had this problem and it was resolved by taking that advice and removing my CSS file from content_scripts .只是为了反对 Beslinda N 的评论,我遇到了这个问题,并通过采纳该建议并从content_scripts删除我的 CSS 文件解决了这个问题。

This might break some of your extension though - as you may want to style normal pages with custom CSS.不过,这可能会破坏您的某些扩展 - 因为您可能希望使用自定义 CSS 设置普通页面的样式。 To solve this problem I created two CSS files, internal.css and external.css .为了解决这个问题,我创建了两个 CSS 文件, internal.cssexternal.css The internal file had all the styling for my popup.html , and the external had the CSS I actually wanted to apply to the extension user's DOM.内部文件具有我的popup.html所有样式,而外部文件具有我实际想要应用于扩展用户的 DOM 的 CSS。 Finally I referenced only external.css in content_scripts .最后我在content_scripts只引用了external.css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM