Goal
Just to clarify: The goal is to is to detect (and close) a tab that has been opened via Chrome's "Duplicate" right-click menu option.
First try
The "Duplicate tab" action works almost exactly like when reloading a page after the user has clicked "Back" then "Forward", so you are basically implementing a version of this question:
function onLoad()
{
if ($('#myStateInput').val() === '') // Load with no state.
$('#myStateInput').val('already loaded'); // Set state
else
alert("Loaded with state. (Duplicate tab or Back + Forward)");
}
Thats great and all, but you only want to detect when you "Duplicate tab". To do this we can blank out the state in onbeforeunload. This works because onbeforeunload gets only called when the user clicks "Back" or "Forward" but not when duplicating a tab.
Second try
function onLoad()
{
if ($('#myStateInput').val() === '') // Load with no state.
$('#myStateInput').val('already loaded'); // Set state
else
alert("Duplicate tab! Do something.");
$(window).on('beforeunload', function() // Back or Forward buttons
{
$('#myStateInput').val(''); // Blank the state out.
});
}