Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Chrome Extension to Capture Open Tabs

Featured Replies

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?

  • Author

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

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

Edited by dap

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.