Jump to content


Photo

Chrome Extension to Capture Open Tabs


  • Please log in to reply
2 replies to this topic

#1 Fee

Fee

    Forum Newcomer

  • Members
  • Pip
  • 15 posts
  • Gender:Male
  • Location:Scotland
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 13 September 2017 - 07:55 AM

Looking for advice from a JavaScript wizard to confirm whether an idea I have is possible. 

 

Basically I am looking to make a Chrome extension that captures a browser session i.e. all the open tabs and saves this as a file on the user's local file system that can be executed to restore the browsing session. Similar to bookmarking - but the user could effectively bookmark a number of related websites and restore them in one click. 

 

I'm at a loss at where to start with this, does anyone have any insights? Is this even possible to achieve in JavaScript? Similarly, is it possible to save a browser executable that opens multiple tabs? 



#2 Fee

Fee

    Forum Newcomer

  • Members
  • Pip
  • 15 posts
  • Gender:Male
  • Location:Scotland
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 16 September 2017 - 04:06 PM

Okay - I've had some progress. I was hoping some people here might have some ideas on how to proceed. 

 

The extension can capture all the open tabs and save this to a user's local file system as a .bat file - using FileSaver.js. However, this just feels a bit... unethical. Rightly so Chrome gives a security warning prior to the download. 

 

I'd really like to generate a HTML file on the fly with inline JavaScript used to open all the captured URLs, this could then be saved to the user's local file system. This method, however, is impossible due to Chrome's pop-up blocking methods. Can anyone think of a smart way around this? 

 

Next step, once this is solved, is to incorporate an interface for naming the file prior to download. Anyway, if anyone is interested, here is the code: 

 

background.js

// background.js
var activeSession = [];

// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {

	//Tab query with no parameters, returns all open tabs. 
	chrome.tabs.query({}, function(tabs){
		//For each tab push to active session array     
		tabs.forEach(function(tab){
			activeSession.push(tab.url);
		});
	});

	//Second query return active tab - neccessary to call content.js
	chrome.tabs.query({active: true, currentWindow: true}, function(active) {
		chrome.tabs.sendMessage(active[0].id, {session: activeSession}, function(response) {
			console.log("Saved");
		});   		
	});
});

content.js

//content.js
var date_time = new Date().toLocaleString()
var fileName = "captured_tabs-" + date_time;

chrome.runtime.onMessage.addListener(
	function(request, sender, sendResponse) {

		var tabs = "";

		console.log(request.session.length)

		for(var i = 0; i < request.session.length; i++){
			tabs += "start chrome.exe " + request.session[i] + "\n";
		}

		var blob = new Blob([tabs], {type: "text/plain;charset=utf-8"});
  		saveAs(blob, fileName+".bat");
	});


#3 dap

dap

    Web Guru

  • Privileged
  • PipPipPipPipPip
  • 1,437 posts
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Designer

Posted 16 September 2017 - 06:46 PM

isn't this jthe same as saving a session? like session buddy extension for example?


Edited by dap, 16 September 2017 - 06:46 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users