简体   繁体   English

chrome.topSites 在 Microsoft Edge (Chromium) 中返回未定义

[英]chrome.topSites returning undefined in Microsoft Edge (Chromium)

I am trying to get the most visited sites in my chrome extension.我正在尝试在我的 chrome 扩展程序中获取访问量最大的网站。 I have been through Chrome Extension Developer Documentation.我已经浏览过 Chrome 扩展开发者文档。

When I trying to get the property topSites from the chrome object, it returning undefined .当我尝试从chrome对象获取属性topSites ,它返回undefined But as per documentation it available since Chrome 36.但根据文档,它自 Chrome 36 起可用。

Even I added permission to access topSites in manifest.json .甚至我在manifest.json添加了访问topSites权限。

 //Load top sites function getTopSites() { chrome.topSites.get((top) => { console.log(top); }); } getTopSites()

When I do print chrome object I find nothing property topSites .当我打印chrome对象时,我没有发现任何属性topSites But documentation mention topSites available.但是文档提到topSites可用的topSites

 //Load top sites function getTopSites() { console.log(chrome); }; getTopSites()

Output in Microsoft Edge Microsoft Edge 中的输出

输出铬对象

"permissions": [
        "activeTab",
        "storage",
        "topSites"
    ]

I am trying to console the output in the browser's console.我试图在浏览器的控制台中控制台输出。

Could anyone tell me what's the problem?谁能告诉我有什么问题?

文档

I try to make a test with chrome.topSites in MS Edge Chromium browser Version 85.0.564.51我尝试在 MS Edge Chromium 浏览器版本 85.0.564.51 中使用chrome.topSites进行测试

I found that it is working fine.我发现它工作正常。

I suggest you try to display it in html file instead of console.我建议您尝试在 html 文件而不是控制台中显示它。

I made a test extension with the below files and code.我使用以下文件和代码制作了一个测试扩展。

popup.html弹出窗口.html

<!DOCTYPE HTML>
<html>
  <body>
    <h2>site list</h2>
    <div id='urls'></div>
    <script src='popup.js'></script>
  </body>
</html>

popup.js弹出窗口.js

function top_site(urls)
{   
    var url= document.getElementById('urls');
    for (var i = 0; i < urls.length; i++) 
    {
        url.innerHTML += urls[i].url + "<br>";      
    }
}

chrome.topSites.get(top_site);

manifest.json清单文件

{
  "name": "sitelist",
  "version": "101",
  "description": "display site list",
  "permissions": ["topSites"],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

Output in Edge browser: Edge浏览器输出:

在此处输入图片说明

Reference for the extension:扩展参考:

Top sites sample Extensions 热门网站示例扩展

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

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