2

I am developing a small page/router component on a website using Angular 7 and its CLI. At one point I need to check if the user has allowed flash, I do this by doing so:

checkFlash() {
  var hasFlash = false;

  try {
    hasFlash = Boolean(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
  } catch (exception) {
    hasFlash = "undefined" != typeof navigator.mimeTypes["application/x-shockwave-flash"];
  }

  return hasFlash;
}

I found this off here, and it works great, but now as I am cleaning up my application I am noticing that Angular doesn't seem to like this, in fact, it says that ActiveXObject isn't defined, yet it still works.

Super confused...

I tried linking an actual flash object like so $('embed[type="application/x-shockwave-flash"]') or $('embed[type="application/x-shockwave-flash"]')[0] but had no luck, it always returned true.

I tried installing extra npm(s) including ones like activex-support and activex-data-support as well as their @types cousins. After setting them up I found out that they did nothing to help my case.

Here are the exact errors the CLI & VScode-Intellisense gave me:

VScode:

[ts] 'ActiveXObject' only refers to a type, but is being used as a value here. [2693] any

CLI:

ERROR in src/app/games/games.component.ts(51,30): error TS2304: Cannot find name 'ActiveXObject'.

It doesn't throw this error when ran inside plain JS, but I've looked around and can't seem to figure out how to run pure JS inside Angular 2 (7). Also looked here with no luck.

Please help, completely lost here.

EDIT: Found the fix --> The answer was here listed inside the comments (will need to make minor changes)(shown below)

  • change from:
checkFlash() {
  var hasFlash = false;

  try {
    hasFlash = Boolean(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
  } catch (exception) {
hasFlash = "undefined" != typeof navigator.mimeTypes["application/x- 
shockwave-flash"];
  }

  return hasFlash;
}
  • to:
function checkFlash() {
    var hasFlash = false;
    try {
        var flash =
            navigator.mimeTypes &&
            navigator.mimeTypes["application/x-shockwave-flash"]
                ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin
                : 0;
        if (flash) hasFlash = true;
    } catch (e) {
        if (navigator.mimeTypes["application/x-shockwave-flash"] != undefined)
            hasFlash = true;
    }

    return hasFlash;
}
255.tar.xz
  • 700
  • 7
  • 23
  • Don't you just love It when about 10 minutes after you ask a question because your so stuck, you find the answer, and waste everyones time, well darn that just happened folks! See the edit if you have this same question and need an answer. – 255.tar.xz Jan 12 '19 at 07:35
  • **I hear this has less IE support**, but who actually uses IE anymore? It's unsecure, buggy, slow, poor design, I could care less about FLASH support detection that works for IE... – 255.tar.xz Jan 12 '19 at 07:50

2 Answers2

6

This issue with ActiveXObject can be solve as shown below: Goto your tsconfig.json file and add the 'scripthost' library. Then recompile your application.

 "lib": [
  "es2017",
  "dom",
  "scripthost"
]
Johnny Camby
  • 578
  • 7
  • 11
0

The answer was here listed inside the comments (will need to make minor changes)(shown below)

change from:

checkFlash() {
  var hasFlash = false;

  try {
    hasFlash = Boolean(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
  } catch (exception) {
hasFlash = "undefined" != typeof navigator.mimeTypes["application/x- 
shockwave-flash"];
  }

  return hasFlash;
}

to:

function checkFlash() {
    var hasFlash = false;
    try {
        var flash =
            navigator.mimeTypes &&
            navigator.mimeTypes["application/x-shockwave-flash"]
                ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin
                : 0;
        if (flash) hasFlash = true;
    } catch (e) {
        if (navigator.mimeTypes["application/x-shockwave-flash"] != undefined)
            hasFlash = true;
    }

    return hasFlash;
}
255.tar.xz
  • 700
  • 7
  • 23