@daisy/ace-axe-runner-electron 1.2.6-alpha.1 → 1.2.6-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/init.js +120 -91
  2. package/package.json +2 -2
  3. package/src/init.js +124 -91
package/lib/init.js CHANGED
@@ -326,7 +326,13 @@ function axeRunnerInit(eventEmmitter, CONCURRENT_INSTANCES) {
326
326
  browserWindow.webContents.session.webRequest.onBeforeRequest({
327
327
  urls: []
328
328
  }, (details, callback) => {
329
- if (details.url && /^https?:\/\//.test(details.url) && (rootUrl && !details.url.startsWith(rootUrl) || !rootUrl && !/^https?:\/\/127.0.0.1/.test(details.url))) {
329
+ if (details.url && (/^file:\/\//.test(details.url) || /^https?:\/\//.test(details.url)
330
+ // && (
331
+ // (rootUrl && !details.url.startsWith(rootUrl))
332
+ // ||
333
+ // (!rootUrl && !/^https?:\/\/127.0.0.1/.test(details.url))
334
+ // )
335
+ )) {
330
336
  if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} onBeforeRequest BLOCK: ${details.url} (${rootUrl})`);
331
337
 
332
338
  // causes ERR_BLOCKED_BY_CLIENT -20 did-fail-load
@@ -759,7 +765,7 @@ new Promise((resolve, reject) => {
759
765
  }
760
766
  axeRunnerInit.todo = true;
761
767
 
762
- const filePathsExpressStaticNotExist = {};
768
+ // const filePathsExpressStaticNotExist = {};
763
769
  function startAxeServer(basedir, scripts, scriptContents) {
764
770
 
765
771
  // NO_HTTP_REMOVE
@@ -832,6 +838,18 @@ function startAxeServer(basedir, scripts, scriptContents) {
832
838
  if (!fs.existsSync(fileSystemPath)) {
833
839
  fileSystemPath = pn;
834
840
  if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} filepath to read (corrected): ${fileSystemPath}`);
841
+ if (!fs.existsSync(fileSystemPath)) {
842
+ if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} FILE DOES NOT EXIST!! ${fileSystemPath}`);
843
+
844
+ const buff = Buffer.from(`<html><body><p>Internal Server Error</p><p>404?! ${fileSystemPath}</p></body></html>`);
845
+ headers["Content-Length"] = buff.length.toString();
846
+ callback({
847
+ data: bufferToStream(buff),
848
+ headers,
849
+ statusCode: 404
850
+ });
851
+ return;
852
+ }
835
853
  }
836
854
 
837
855
  // let html = fs.readFileSync(fileSystemPath, { encoding: "utf8" });
@@ -894,6 +912,18 @@ function startAxeServer(basedir, scripts, scriptContents) {
894
912
  if (!fs.existsSync(fileSystemPath)) {
895
913
  fileSystemPath = pn;
896
914
  if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} --filepath to read (corrected): ${fileSystemPath}`);
915
+ if (!fs.existsSync(fileSystemPath)) {
916
+ if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} --FILE DOES NOT EXIST!! ${fileSystemPath}`);
917
+
918
+ const buff = Buffer.from(`<html><body><p>Internal Server Error</p><p>404?! ${fileSystemPath}</p></body></html>`);
919
+ headers["Content-Length"] = buff.length.toString();
920
+ callback({
921
+ data: bufferToStream(buff),
922
+ headers,
923
+ statusCode: 404
924
+ });
925
+ return;
926
+ }
897
927
  }
898
928
  try {
899
929
  let mediaType = mime.lookup(fileSystemPath) || "stream/octet";
@@ -920,95 +950,94 @@ function startAxeServer(basedir, scripts, scriptContents) {
920
950
  });
921
951
  }
922
952
 
923
- if (isDev) {
924
- // handle WebInspector JS maps etc.
925
-
926
- // const url = new URL(`https://fake.org${req.url}`);
927
- // const pathname = url.pathname;
928
- const pathname = decodeURI(u.pathname);
929
-
930
- const filePath = path.join(basedir, pathname);
931
- if (filePathsExpressStaticNotExist[filePath]) {
932
-
933
- const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
934
- headers["Content-Length"] = buff.length.toString();
935
- headers["Content-Type"] = "plain/text";
936
- callback({
937
- data: bufferToStream(buff),
938
- headers,
939
- statusCode: 404
940
- });
941
- return;
942
- }
943
- fsOriginal.exists(filePath, exists => {
944
- if (exists) {
945
- fsOriginal.readFile(filePath, undefined, (err, data) => {
946
- if (err) {
947
- if (LOG_DEBUG) {
948
- console.log(`${ACE_LOG_PREFIX} HTTP FAIL fsOriginal.exists && ERR ${basedir} + ${req.url} => ${filePath}`, err);
949
- }
950
- filePathsExpressStaticNotExist[filePath] = err.toString();
951
- const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
952
- headers["Content-Length"] = buff.length.toString();
953
- headers["Content-Type"] = "plain/text";
954
- callback({
955
- data: bufferToStream(buff),
956
- headers,
957
- statusCode: 404
958
- });
959
- } else {
960
- // if (LOG_DEBUG) {
961
- // console.log(`${ACE_LOG_PREFIX} HTTP OK fsOriginal.exists ${basedir} + ${req.url} => ${filePath}`);
962
- // }
963
- callback({
964
- data: null,
965
- headers,
966
- statusCode: 500
967
- });
968
- }
969
- });
970
- } else {
971
- fs.exists(filePath, exists => {
972
- if (exists) {
973
- fs.readFile(filePath, undefined, (err, data) => {
974
- if (err) {
975
- if (LOG_DEBUG) {
976
- console.log(`${ACE_LOG_PREFIX} HTTP FAIL !fsOriginal.exists && fs.exists && ERR ${basedir} + ${req.url} => ${filePath}`, err);
977
- }
978
- filePathsExpressStaticNotExist[filePath] = err.toString();
979
- const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
980
- headers["Content-Length"] = buff.length.toString();
981
- headers["Content-Type"] = "plain/text";
982
- callback({
983
- data: bufferToStream(buff),
984
- headers,
985
- statusCode: 404
986
- });
987
- } else {
988
- if (LOG_DEBUG) {
989
- console.log(`${ACE_LOG_PREFIX} HTTP OK !fsOriginal.exists && fs.exists ${basedir} + ${req.url} => ${filePath}`);
990
- }
991
- callback({
992
- data: null,
993
- headers,
994
- statusCode: 500
995
- });
996
- }
997
- });
998
- } else {
999
- if (LOG_DEBUG) {
1000
- console.log(`${ACE_LOG_PREFIX} HTTP FAIL !fsOriginal.exists && !fs.exists ${basedir} + ${req.url} => ${filePath}`);
1001
- }
1002
- callback({
1003
- data: null,
1004
- headers,
1005
- statusCode: 404
1006
- });
1007
- }
1008
- });
1009
- }
1010
- });
1011
- }
953
+ // if (isDev) { // handle WebInspector JS maps etc.
954
+
955
+ // // const url = new URL(`https://fake.org${req.url}`);
956
+ // // const pathname = url.pathname;
957
+ // const pathname = decodeURI(u.pathname);
958
+
959
+ // const filePath = path.join(basedir, pathname);
960
+ // if (filePathsExpressStaticNotExist[filePath]) {
961
+
962
+ // const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
963
+ // headers["Content-Length"] = buff.length.toString();
964
+ // headers["Content-Type"] = "plain/text";
965
+ // callback({
966
+ // data: bufferToStream(buff),
967
+ // headers,
968
+ // statusCode: 404,
969
+ // });
970
+ // return;
971
+ // }
972
+ // fsOriginal.exists(filePath, (exists) => {
973
+ // if (exists) {
974
+ // fsOriginal.readFile(filePath, undefined, (err, data) => {
975
+ // if (err) {
976
+ // if (LOG_DEBUG) {
977
+ // console.log(`${ACE_LOG_PREFIX} HTTP FAIL fsOriginal.exists && ERR ${basedir} + ${req.url} => ${filePath}`, err);
978
+ // }
979
+ // filePathsExpressStaticNotExist[filePath] = err.toString();
980
+ // const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
981
+ // headers["Content-Length"] = buff.length.toString();
982
+ // headers["Content-Type"] = "plain/text";
983
+ // callback({
984
+ // data: bufferToStream(buff),
985
+ // headers,
986
+ // statusCode: 404,
987
+ // });
988
+ // } else {
989
+ // // if (LOG_DEBUG) {
990
+ // // console.log(`${ACE_LOG_PREFIX} HTTP OK fsOriginal.exists ${basedir} + ${req.url} => ${filePath}`);
991
+ // // }
992
+ // callback({
993
+ // data: null,
994
+ // headers,
995
+ // statusCode: 500,
996
+ // });
997
+ // }
998
+ // });
999
+ // } else {
1000
+ // fs.exists(filePath, (exists) => {
1001
+ // if (exists) {
1002
+ // fs.readFile(filePath, undefined, (err, data) => {
1003
+ // if (err) {
1004
+ // if (LOG_DEBUG) {
1005
+ // console.log(`${ACE_LOG_PREFIX} HTTP FAIL !fsOriginal.exists && fs.exists && ERR ${basedir} + ${req.url} => ${filePath}`, err);
1006
+ // }
1007
+ // filePathsExpressStaticNotExist[filePath] = err.toString();
1008
+ // const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
1009
+ // headers["Content-Length"] = buff.length.toString();
1010
+ // headers["Content-Type"] = "plain/text";
1011
+ // callback({
1012
+ // data: bufferToStream(buff),
1013
+ // headers,
1014
+ // statusCode: 404,
1015
+ // });
1016
+ // } else {
1017
+ // if (LOG_DEBUG) {
1018
+ // console.log(`${ACE_LOG_PREFIX} HTTP OK !fsOriginal.exists && fs.exists ${basedir} + ${req.url} => ${filePath}`);
1019
+ // }
1020
+ // callback({
1021
+ // data: null,
1022
+ // headers,
1023
+ // statusCode: 500,
1024
+ // });
1025
+ // }
1026
+ // });
1027
+ // } else {
1028
+ // if (LOG_DEBUG) {
1029
+ // console.log(`${ACE_LOG_PREFIX} HTTP FAIL !fsOriginal.exists && !fs.exists ${basedir} + ${req.url} => ${filePath}`);
1030
+ // }
1031
+ // callback({
1032
+ // data: null,
1033
+ // headers,
1034
+ // statusCode: 404,
1035
+ // });
1036
+ // }
1037
+ // });
1038
+ // }
1039
+ // });
1040
+ // }
1012
1041
  };
1013
1042
 
1014
1043
  // NO_HTTP_REMOVE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daisy/ace-axe-runner-electron",
3
- "version": "1.2.6-alpha.1",
3
+ "version": "1.2.6-alpha.3",
4
4
  "engines": {
5
5
  "node": ">=12.0.0",
6
6
  "yarn": "^1.22.0",
@@ -23,7 +23,7 @@
23
23
  "license": "MIT",
24
24
  "main": "lib/index.js",
25
25
  "dependencies": {
26
- "@daisy/ace-cli-shared": "^1.2.6-alpha.1",
26
+ "@daisy/ace-cli-shared": "^1.2.6-alpha.3",
27
27
  "mime-types": "^2.1.34",
28
28
  "uuid": "^8.3.2"
29
29
  },
package/src/init.js CHANGED
@@ -333,8 +333,17 @@ function axeRunnerInit(eventEmmitter, CONCURRENT_INSTANCES) {
333
333
  urls: [],
334
334
  }, (details, callback) => {
335
335
  if (details.url
336
- && /^https?:\/\//.test(details.url)
337
- && ((rootUrl && !details.url.startsWith(rootUrl)) || (!rootUrl && !/^https?:\/\/127.0.0.1/.test(details.url)))
336
+ &&
337
+ (
338
+ /^file:\/\//.test(details.url)
339
+ ||
340
+ /^https?:\/\//.test(details.url)
341
+ // && (
342
+ // (rootUrl && !details.url.startsWith(rootUrl))
343
+ // ||
344
+ // (!rootUrl && !/^https?:\/\/127.0.0.1/.test(details.url))
345
+ // )
346
+ )
338
347
  ) {
339
348
  if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} onBeforeRequest BLOCK: ${details.url} (${rootUrl})`);
340
349
 
@@ -780,7 +789,7 @@ new Promise((resolve, reject) => {
780
789
  }
781
790
  axeRunnerInit.todo = true;
782
791
 
783
- const filePathsExpressStaticNotExist = {};
792
+ // const filePathsExpressStaticNotExist = {};
784
793
  function startAxeServer(basedir, scripts, scriptContents) {
785
794
 
786
795
  // NO_HTTP_REMOVE
@@ -856,6 +865,18 @@ function startAxeServer(basedir, scripts, scriptContents) {
856
865
  if (!fs.existsSync(fileSystemPath)) {
857
866
  fileSystemPath = pn;
858
867
  if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} filepath to read (corrected): ${fileSystemPath}`);
868
+ if (!fs.existsSync(fileSystemPath)) {
869
+ if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} FILE DOES NOT EXIST!! ${fileSystemPath}`);
870
+
871
+ const buff = Buffer.from(`<html><body><p>Internal Server Error</p><p>404?! ${fileSystemPath}</p></body></html>`);
872
+ headers["Content-Length"] = buff.length.toString();
873
+ callback({
874
+ data: bufferToStream(buff),
875
+ headers,
876
+ statusCode: 404,
877
+ });
878
+ return;
879
+ }
859
880
  }
860
881
 
861
882
  // let html = fs.readFileSync(fileSystemPath, { encoding: "utf8" });
@@ -918,6 +939,18 @@ function startAxeServer(basedir, scripts, scriptContents) {
918
939
  if (!fs.existsSync(fileSystemPath)) {
919
940
  fileSystemPath = pn;
920
941
  if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} --filepath to read (corrected): ${fileSystemPath}`);
942
+ if (!fs.existsSync(fileSystemPath)) {
943
+ if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} --FILE DOES NOT EXIST!! ${fileSystemPath}`);
944
+
945
+ const buff = Buffer.from(`<html><body><p>Internal Server Error</p><p>404?! ${fileSystemPath}</p></body></html>`);
946
+ headers["Content-Length"] = buff.length.toString();
947
+ callback({
948
+ data: bufferToStream(buff),
949
+ headers,
950
+ statusCode: 404,
951
+ });
952
+ return;
953
+ }
921
954
  }
922
955
  try {
923
956
  let mediaType = mime.lookup(fileSystemPath) || "stream/octet";
@@ -944,94 +977,94 @@ function startAxeServer(basedir, scripts, scriptContents) {
944
977
  });
945
978
  }
946
979
 
947
- if (isDev) { // handle WebInspector JS maps etc.
948
-
949
- // const url = new URL(`https://fake.org${req.url}`);
950
- // const pathname = url.pathname;
951
- const pathname = decodeURI(u.pathname);
952
-
953
- const filePath = path.join(basedir, pathname);
954
- if (filePathsExpressStaticNotExist[filePath]) {
955
-
956
- const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
957
- headers["Content-Length"] = buff.length.toString();
958
- headers["Content-Type"] = "plain/text";
959
- callback({
960
- data: bufferToStream(buff),
961
- headers,
962
- statusCode: 404,
963
- });
964
- return;
965
- }
966
- fsOriginal.exists(filePath, (exists) => {
967
- if (exists) {
968
- fsOriginal.readFile(filePath, undefined, (err, data) => {
969
- if (err) {
970
- if (LOG_DEBUG) {
971
- console.log(`${ACE_LOG_PREFIX} HTTP FAIL fsOriginal.exists && ERR ${basedir} + ${req.url} => ${filePath}`, err);
972
- }
973
- filePathsExpressStaticNotExist[filePath] = err.toString();
974
- const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
975
- headers["Content-Length"] = buff.length.toString();
976
- headers["Content-Type"] = "plain/text";
977
- callback({
978
- data: bufferToStream(buff),
979
- headers,
980
- statusCode: 404,
981
- });
982
- } else {
983
- // if (LOG_DEBUG) {
984
- // console.log(`${ACE_LOG_PREFIX} HTTP OK fsOriginal.exists ${basedir} + ${req.url} => ${filePath}`);
985
- // }
986
- callback({
987
- data: null,
988
- headers,
989
- statusCode: 500,
990
- });
991
- }
992
- });
993
- } else {
994
- fs.exists(filePath, (exists) => {
995
- if (exists) {
996
- fs.readFile(filePath, undefined, (err, data) => {
997
- if (err) {
998
- if (LOG_DEBUG) {
999
- console.log(`${ACE_LOG_PREFIX} HTTP FAIL !fsOriginal.exists && fs.exists && ERR ${basedir} + ${req.url} => ${filePath}`, err);
1000
- }
1001
- filePathsExpressStaticNotExist[filePath] = err.toString();
1002
- const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
1003
- headers["Content-Length"] = buff.length.toString();
1004
- headers["Content-Type"] = "plain/text";
1005
- callback({
1006
- data: bufferToStream(buff),
1007
- headers,
1008
- statusCode: 404,
1009
- });
1010
- } else {
1011
- if (LOG_DEBUG) {
1012
- console.log(`${ACE_LOG_PREFIX} HTTP OK !fsOriginal.exists && fs.exists ${basedir} + ${req.url} => ${filePath}`);
1013
- }
1014
- callback({
1015
- data: null,
1016
- headers,
1017
- statusCode: 500,
1018
- });
1019
- }
1020
- });
1021
- } else {
1022
- if (LOG_DEBUG) {
1023
- console.log(`${ACE_LOG_PREFIX} HTTP FAIL !fsOriginal.exists && !fs.exists ${basedir} + ${req.url} => ${filePath}`);
1024
- }
1025
- callback({
1026
- data: null,
1027
- headers,
1028
- statusCode: 404,
1029
- });
1030
- }
1031
- });
1032
- }
1033
- });
1034
- }
980
+ // if (isDev) { // handle WebInspector JS maps etc.
981
+
982
+ // // const url = new URL(`https://fake.org${req.url}`);
983
+ // // const pathname = url.pathname;
984
+ // const pathname = decodeURI(u.pathname);
985
+
986
+ // const filePath = path.join(basedir, pathname);
987
+ // if (filePathsExpressStaticNotExist[filePath]) {
988
+
989
+ // const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
990
+ // headers["Content-Length"] = buff.length.toString();
991
+ // headers["Content-Type"] = "plain/text";
992
+ // callback({
993
+ // data: bufferToStream(buff),
994
+ // headers,
995
+ // statusCode: 404,
996
+ // });
997
+ // return;
998
+ // }
999
+ // fsOriginal.exists(filePath, (exists) => {
1000
+ // if (exists) {
1001
+ // fsOriginal.readFile(filePath, undefined, (err, data) => {
1002
+ // if (err) {
1003
+ // if (LOG_DEBUG) {
1004
+ // console.log(`${ACE_LOG_PREFIX} HTTP FAIL fsOriginal.exists && ERR ${basedir} + ${req.url} => ${filePath}`, err);
1005
+ // }
1006
+ // filePathsExpressStaticNotExist[filePath] = err.toString();
1007
+ // const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
1008
+ // headers["Content-Length"] = buff.length.toString();
1009
+ // headers["Content-Type"] = "plain/text";
1010
+ // callback({
1011
+ // data: bufferToStream(buff),
1012
+ // headers,
1013
+ // statusCode: 404,
1014
+ // });
1015
+ // } else {
1016
+ // // if (LOG_DEBUG) {
1017
+ // // console.log(`${ACE_LOG_PREFIX} HTTP OK fsOriginal.exists ${basedir} + ${req.url} => ${filePath}`);
1018
+ // // }
1019
+ // callback({
1020
+ // data: null,
1021
+ // headers,
1022
+ // statusCode: 500,
1023
+ // });
1024
+ // }
1025
+ // });
1026
+ // } else {
1027
+ // fs.exists(filePath, (exists) => {
1028
+ // if (exists) {
1029
+ // fs.readFile(filePath, undefined, (err, data) => {
1030
+ // if (err) {
1031
+ // if (LOG_DEBUG) {
1032
+ // console.log(`${ACE_LOG_PREFIX} HTTP FAIL !fsOriginal.exists && fs.exists && ERR ${basedir} + ${req.url} => ${filePath}`, err);
1033
+ // }
1034
+ // filePathsExpressStaticNotExist[filePath] = err.toString();
1035
+ // const buff = Buffer.from(filePathsExpressStaticNotExist[filePath]);
1036
+ // headers["Content-Length"] = buff.length.toString();
1037
+ // headers["Content-Type"] = "plain/text";
1038
+ // callback({
1039
+ // data: bufferToStream(buff),
1040
+ // headers,
1041
+ // statusCode: 404,
1042
+ // });
1043
+ // } else {
1044
+ // if (LOG_DEBUG) {
1045
+ // console.log(`${ACE_LOG_PREFIX} HTTP OK !fsOriginal.exists && fs.exists ${basedir} + ${req.url} => ${filePath}`);
1046
+ // }
1047
+ // callback({
1048
+ // data: null,
1049
+ // headers,
1050
+ // statusCode: 500,
1051
+ // });
1052
+ // }
1053
+ // });
1054
+ // } else {
1055
+ // if (LOG_DEBUG) {
1056
+ // console.log(`${ACE_LOG_PREFIX} HTTP FAIL !fsOriginal.exists && !fs.exists ${basedir} + ${req.url} => ${filePath}`);
1057
+ // }
1058
+ // callback({
1059
+ // data: null,
1060
+ // headers,
1061
+ // statusCode: 404,
1062
+ // });
1063
+ // }
1064
+ // });
1065
+ // }
1066
+ // });
1067
+ // }
1035
1068
  };
1036
1069
 
1037
1070
  // NO_HTTP_REMOVE