获取文档 DOM 对象从标签对象

huangapple go评论50阅读模式
英文:

How to get document DOM object from Tab object

问题

以下是您要翻译的内容:

我正在编写一个Firefox插件,我想要在其中打开一个新的空白页面,然后在一个新的标签页中更新其DOM内容。

相关调用是:

browser.tabs.create({url: 'about:blank'}).then(tab => {
  console.log('Tab: ' + tab);
  Object.keys(tab).forEach((prop) => console.log(prop));
  window.document.innerHTML = '<h1>Lol</h1>';
});

然而,这并不会更新新标签页中的页面。
官方文档中,我找不到可以用来获取其文档/ DOM内容的结果Tab对象的属性。

英文:

I am writing a Firefox plugin in which I want to open a new blank page and then update its DOM content in a new tab.

The relevant call is:

browser.tabs.create({url: &#39;about:blank&#39;}).then(tab =&gt; {
  console.log(&#39;Tab: &#39; + tab);
  Object.keys(tab).forEach((prop)=&gt; console.log(prop));
  window.document.innerHTML = &#39;&lt;h1&gt;Lol&lt;/h1&gt;&#39;;
});

However, this does not update the page in the new tab.
In the official docs I cannot find a property of the resulting Tab object that I could use to get its document / DOM content.

答案1

得分: 1

背景脚本无法访问网页。这是由内容脚本完成的。

英文:

Background scripts cannot access a web page. This is a work for a content script.

huangapple
  • 本文由 发表于 2023年6月15日 08:34:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76478371.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定