使用chrome获取所有打开的标签的URL,并将其发送到Web服务 [英] Get urls of all open tabs in chrome, and send it to a web service

查看:121
本文介绍了使用chrome获取所有打开的标签的URL,并将其发送到Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Chrome扩展程序,以获取所有打开的标签的URL,并将它们全部保存,以将它们发送到域。因此,我需要2个步骤:


  1. 获取所有打开的选项卡的URL并将它们存储在数组或像
    那样的东西中。

  2. 将所有网址的数组发送到域。
  3. >

    查看 chrome.windows.getAll 获取打开的窗口列表。每个窗口都有一个选项卡属性,其中包含窗口中的选项卡列表。每个标签都有一个 url 属性。请参阅标签文档



    您需要遍历窗口,然后遍历每个窗口中的选项卡,并将它们添加到您的数组中,然后执行您想要的任何操作。



    通常情况下,您无法这样做,但具有必要权限的Chrome扩展程序可以执行跨源XMLHttpRequest 。您需要将该列表发送到其他域。



    您可以使用 JSON.stringify 来转换将数组转换为可以发送的字符串,然后在服务器端使用一些类似的函数将其转换回数组。


    I am making a chrome extension to get urls of all open tabs and save them all to send them to a domain.so i require 2 steps:

    1. Get urls of all open tabs and store them in an array or stuff like that.
    2. Send the array of all urls to a domain.

    解决方案

    Look at chrome.windows.getAll to get a list of open windows. Each window has a tabs property that contains a list of tabs in the window. Each tab has a url property. See tabs documentation.

    You'll want to loop over the windows, and then the tabs in each window, and add these to your array and then do whatever it is you want to do.

    Normally you can't do this, but chrome extensions with the necessary permissions are allowed to do Cross-Origin XMLHttpRequest. You'll need that to send the list to the other domain.

    You can use JSON.stringify to convert an array to a string that you can send and then some similar function on the server side to convert it back to an array.

    这篇关于使用chrome获取所有打开的标签的URL,并将其发送到Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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