If you use an Execute Javascript action in Chrome or Safari, you can gather document title and url, but also use XPath expressions to look for the text of the most recent heading (before the selection) and any #anchor id or name that may be attached to that heading.
// ver 0.1 Rob Trew @complexpoint 2015
(function () {
'use strict';
var nodeSeln = window.getSelection().anchorNode,
lstH = [1, 2, 3, 4, 5, 6],
strInHeading = lstH.map(function (x) {
return 'ancestor-or-self::h' + x;
}).join(' or '),
lstAnchor = [
'*[' + lstH.map(function (x) {
return 'self::h' + x;
}).join(' or ') + ']//*',
'a[string(@name) and (' + strInHeading + ')]',
'*[string(@id) and (' + strInHeading + ')]'
].map(function (strType) {
var strPath = './preceding::' + strType + '[1]',
oNode = document.evaluate(
strPath,
nodeSeln,
null, 0, 0
).iterateNext(),
strTag;
return oNode ? {
text: oNode.hasChildNodes() ?
oNode.firstChild.textContent : oNode.textContent,
tag: (strTag = oNode.getAttribute('name')) ?
strTag : oNode.getAttribute('id')
} : {};
}),
strHead = lstAnchor[0].text || lstAnchor[1].text || lstAnchor[2].text,
dctName = lstAnchor[1],
dctID = lstAnchor[2];
// Page name, url, heading text, heading #id or #name
return [
document.title,
document.URL.split('#')[0], // drop any page=load anchor
strHead,
strHead ? ( // get any local anchor for the selection
(dctName.text === strHead) ? dctName.tag :
(dctID.text === strHead) ? dctID.tag : ''
) : ''
].join(' ');
})();