google-chrome-extension - 如何将 postman 历史记录从 Chrome 应用程序复制到 native 应用程序?

标签 google-chrome-extension google-chrome-app postman

由于 Google 现已终止对 Chrome 应用程序的支持。最近,Postman 弃用了他们的 Chrome 应用程序并引入了 native 应用程序。

我正在从 postman Chrome 应用程序切换到 native 应用程序。

如何将历史记录从 Chrome 应用程序复制到 native 应用程序。同步不起作用。 有一个选项可以导出数据,但不会导出历史记录。

有什么想法吗?

最佳答案

所以在搜索这个时我遇到了 this帖子非常有帮助。 感谢斯蒂芬分享此代码。 按照以下步骤将您的历史记录从 Chrome 应用复制到 native 应用。

//In Chrome DevTools on the background page of the Postman extension...

//A handy helper method that lets you save data from the console to a file
(function(console){

console.save = function(data, filename){

    if(!data) {
        console.error('Console.save: No data')
        return;
    }

    if(!filename) filename = 'console.json'

    if(typeof data === "object"){
        data = JSON.stringify(data, undefined, 4)
    }

    var blob = new Blob([data], {type: 'text/json'}),
        e    = document.createEvent('MouseEvents'),
        a    = document.createElement('a')

    a.download = filename
    a.href = window.URL.createObjectURL(blob)
    a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
    e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
    a.dispatchEvent(e)
}
})(console)

//Common error reporting function
function reportError(){
console.error('Oops, something went wrong :-(');
}

//Open the database
var dbReq = indexedDB.open('postman')
dbReq.onerror = reportError;
dbReq.onsuccess = function(){
var db = dbReq.result;

//Query for all the saved requests
var requestReq = db.transaction(["requests"],"readwrite").objectStore('requests').getAll();
requestReq.onerror = reportError;
requestReq.onsuccess = function(){
	var requests = requestReq.result;
	
	//Dump them to a file
	console.save(JSON.stringify(requests), 'postman-requests-export.json')
	console.info('Your existing requests have been exported to a file and downloaded to your computer.  You will need to copy the contents of that file for the next part')
};
};


//Switch to standalone app and open the dev console

//Paste the text from the exported file here (overwriting the empty array)
var data = [] 

//Enter the guid/id of the workspace to import into.  Run the script with this value blank if you need some help
//  finding this value.  Also, be sure you don't end up with extra quotes if you copy/paste the value
var ws = ''; 

//Common error reporting function
function reportError(){
console.error('Oops, something went wrong :-(');
}

//Open the database
var dbReq = indexedDB.open('postman-app')
dbReq.onerror = reportError;
dbReq.onsuccess = function(){
var db = dbReq.result;

if(!data.length){
	console.error('You did not pass in any exported requests so there is nothing for this script to do.  Perhaps you forgot to paste your request data?');
	return;
}

if(!ws){
	var wsReq = db.transaction(["workspace"],"readwrite").objectStore('workspace').getAll();
	wsReq.onerror = reportError;
	wsReq.onsuccess = function(){
		console.error('You did not specify a workspace.  Below is a dump of all your workspaces.  Grab the guid (ID field) from the workspace you want these requests to show up under and include it at the top of this script');
		console.log(wsReq.result);
	}
	return;
}

data.forEach(function(a){
	a.workspace = ws;
	db.transaction(["history"],"readwrite").objectStore('history').add(a);
});

console.log('Requests have been imported.  Give it a second to finish up and then restart Postman')
}
//Restart Postman

注意:

1.要在 Chrome 应用程序上使用 DevTools,您需要在
中启用以下标志 chrome://flags flag

2.然后右键单击并检查您的 chrome postman 应用程序。

3.在 native 应用程序上使用 DevTools ctrl+shift+I (view->showDevTools)

关于google-chrome-extension - 如何将 postman 历史记录从 Chrome 应用程序复制到 native 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47105706/

相关文章:

jquery - Chrome 打包应用程序无法与 jquery 和 jquery mobile 配合使用

javascript - Chrome 应用程序在全屏中创建新窗口 - html 元素不是全高

json - Postman Jetpack 解析 json 响应

node.js - Newman.run 导致 heapUsed 增加但在迭代中重复时不会释放内存

google-chrome-extension - chrome.extension.onMessage.addListener 无法读取未定义的属性 'onMessage'

javascript - 同时打开多个窗口、弹出窗口和新选项卡

css - 防止页面 CSS 影响 Chrome 扩展 CSS

javascript - 当不同用户安装时,Chrome 扩展程序如何与自身对话?

google-chrome - 在谷歌浏览器中禁用检查元素、右键单击和 F12

laravel - postman 返回 HTML 而不是 JSON?