tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

utils.js (1414B)


      1 function determineInjectionSinkDescription(testCase) {
      2    const targetWindowDescription = ("targetWindow" in testCase) ?
      3      testCase.targetWindow.name : "";
      4 
      5    const element = ("elementId" in testCase) ?
      6      window.document.getElementById(testCase.elementId) : null;
      7 
      8    const elementDescription = element ? (element.localName +
      9        (element.target ? ("[target=" + element.target + "]") : "")) : null;
     10 
     11    return ((elementDescription ? (elementDescription + ".") :
     12      (targetWindowDescription ? (targetWindowDescription + ".") : ""))) +
     13      testCase.propertySequence.join(".");
     14 }
     15 
     16 function assignJavascriptURLToInjectionSink(testCase) {
     17  const element = ("elementId" in testCase) ?
     18    document.getElementById(testCase.elementId) : null;
     19 
     20  let currentObject = element ? element : testCase.targetWindow;
     21 
     22  const propertySequence = testCase.propertySequence;
     23  for (let i = 0; i < propertySequence.length - 1; ++i) {
     24    currentObject = currentObject[propertySequence[i]];
     25  }
     26 
     27  currentObject[propertySequence.at(-1)] =
     28    "javascript:parent.postMessage('executed', '*')";
     29 
     30  if ("navigationFunction" in testCase) {
     31    element[testCase.navigationFunction]();
     32  }
     33 }
     34 
     35 function encodeURIWithApostrophes(uriWithApostrophes) {
     36  const encodedURI = encodeURI(uriWithApostrophes);
     37  // https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding
     38  return encodedURI.replaceAll("'","%27");
     39 }