Jump to content
Sign in to follow this  
Fee

Chrome Extension to Capture Open Tabs

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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");
	});

Share this post


Link to post
Share on other sites

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

Edited by dap

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing

    No registered users viewing this page.

  • Member Statistics

    • Total Members
      57,553
    • Most Online
      4,970

    Newest Member
    Skilton06
    Joined
  • Forum Statistics

    • Total Topics
      65,740
    • Total Posts
      455,352
×