谷歌插件 chrome.cookies.getAll API获取登录网站的cookie信息
- 代码实现
- 效果图
代码实现
<div class="layui-form-item"><label class="layui-form-label">链接:</label><div class="layui-input-block"><input type="text" name="url" id="cookielinks" placeholder="请输入链接地址" class="layui-input" lay-verify="required"/></div>
</div><button class="layui-btn" lay-submit lay-filter="cookieLinkBtn">cookie采集</button><table id="cookieDataTable" class="dataTable"></table>
form.on('submit(cookieLinkBtn)', function () {let cookieLink = $("#cookielinks").val().trim();var req = new XMLHttpRequest();req.onload = function () {if(req.status == 200){// chrome.cookie.getAll 获取cookie信息chrome.cookies.getAll({url: cookieLink// name:属性用于指定需要返回的cookie value值,如指定UserName,就只有一条记录返回// name: "UserName" }, function (cookies) {console.log("查到 " + cookies.length + " 条cookies");console.log("查到的cookie信息:", cookies);// cookie数据渲染到表格init_cookie_table(cookies);});}}req.open("GET", cookieLink, true);req.send(null);return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。});function init_cookie_table(data) {table.render({elem: '#cookieDataTable',data: data,even: true,page: true,limits: [20, 50, 100],limit: 20,cols: [[{field: "domain", title:"domain", width: '10%', align: 'center'},{field: "expirationDate", title:"expirationDate", width: '10%', align: 'center'},{field: "hostOnly", title:"hostOnly", width: '10%', align: 'center'},{field: "httpOnly", title:"httpOnly", width: '10%', align: 'center'},{field: "name", title:"name", width: '10%', align: 'center'},{field: "value", title:"value", width: '10%', align: 'center', templet: function (d) {return unescape(d.value);}},{field: "path", title:"path", width: '10%', align: 'center'},{field: "sameSite", title:"sameSite", width: '10%', align: 'center'},{field: "secure", title:"secure", width: '10%', align: 'center'},{field: "session", title:"session", width: '10%', align: 'center'},{field: "storeId", title:"storeId", width: '10%', align: 'center'}]]});}
另外需要在manifest.json中,permissions需要引入cookies信息
"permissions": ["*://*/*", // 访问权限可以设置匹配全部"cookies"]
效果图
这里我输入的是登录csdn的地址
https://www.csdn.net/
这里只截取了部分信息
查看详细Chrome API(中文版)