-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Changement de la méthode d'analyse en recréant le DOM de la pag…
…e en mémoire. Cela évite de charge le code de l'analyseur dans la page elle même. Cela permet d'analyser des sites ayant des Content Security Policy de configurés. Ces modifications sont issues de la proposition de @hayaofr (via #16), j'ai simplement ici réduit au maximum le nombre de modification pour faciliter la relecture de la PR Fix: #19
- Loading branch information
Showing
35 changed files
with
1,310 additions
and
794 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,7 @@ function getImagesResizedInBrowser() { | |
}); | ||
return imagesResized; | ||
} | ||
|
||
module.exports = { | ||
start_analyse_core | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const {translator} = require("../cli-core/translator"); | ||
|
||
chrome = { | ||
"i18n": { | ||
"getMessage": function (message, parameters = []) { | ||
return translator.getCatalog()[message].replace(/%s/g, function () { | ||
// parameters is string or array | ||
return Array.isArray(parameters) ? parameters.shift() : parameters; | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = { | ||
chrome | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
rulesManager.registerRule({ | ||
complianceLevel: 'A', | ||
id: "AddExpiresOrCacheControlHeaders", | ||
comment: "", | ||
detailComment: "", | ||
const { chrome } = require("../chrome"); | ||
const {isStaticRessource, hasValidCacheHeaders} = require("../utils"); | ||
|
||
check: function (measures) { | ||
let staticResourcesSize = 0; | ||
let staticResourcesWithCache = 0; | ||
function registerAddExpiresOrCacheControlHeaders(rulesManager) { | ||
rulesManager.registerRule({ | ||
complianceLevel: 'A', | ||
id: "AddExpiresOrCacheControlHeaders", | ||
comment: "", | ||
detailComment: "", | ||
|
||
if (measures.entries.length) measures.entries.forEach(entry => { | ||
if (isStaticRessource(entry)) { | ||
staticResourcesSize += entry.response.content.size; | ||
if (hasValidCacheHeaders(entry)) { | ||
staticResourcesWithCache += entry.response.content.size; | ||
check: function (measures) { | ||
let staticResourcesSize = 0; | ||
let staticResourcesWithCache = 0; | ||
|
||
if (measures.entries.length) measures.entries.forEach(entry => { | ||
if (isStaticRessource(entry)) { | ||
staticResourcesSize += entry.response.content.size; | ||
if (hasValidCacheHeaders(entry)) { | ||
staticResourcesWithCache += entry.response.content.size; | ||
} | ||
else this.detailComment += chrome.i18n.getMessage("rule_AddExpiresOrCacheControlHeaders_DetailComment", `${entry.request.url} ${Math.round(entry.response.content.size / 100) / 10}`) + '<br>'; | ||
} | ||
else this.detailComment += chrome.i18n.getMessage("rule_AddExpiresOrCacheControlHeaders_DetailComment",`${entry.request.url} ${Math.round(entry.response.content.size / 100) / 10}`) + '<br>'; | ||
} | ||
}); | ||
}); | ||
|
||
if (staticResourcesSize > 0) { | ||
const cacheHeaderRatio = staticResourcesWithCache / staticResourcesSize * 100; | ||
if (cacheHeaderRatio < 95) { | ||
if (cacheHeaderRatio < 90) this.complianceLevel = 'C' | ||
else this.complianceLevel = 'B'; | ||
if (staticResourcesSize > 0) { | ||
const cacheHeaderRatio = staticResourcesWithCache / staticResourcesSize * 100; | ||
if (cacheHeaderRatio < 95) { | ||
if (cacheHeaderRatio < 90) this.complianceLevel = 'C' | ||
else this.complianceLevel = 'B'; | ||
} | ||
else this.complianceLevel = 'A'; | ||
this.comment = chrome.i18n.getMessage("rule_AddExpiresOrCacheControlHeaders_Comment", String(Math.round(cacheHeaderRatio * 10) / 10) + "%"); | ||
} | ||
else this.complianceLevel = 'A'; | ||
this.comment = chrome.i18n.getMessage("rule_AddExpiresOrCacheControlHeaders_Comment", String(Math.round(cacheHeaderRatio * 10) / 10) + "%"); | ||
} | ||
} | ||
}, "harReceived"); | ||
}, "harReceived"); | ||
} | ||
|
||
module.exports = { | ||
registerAddExpiresOrCacheControlHeaders | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
rulesManager.registerRule({ | ||
complianceLevel: 'A', | ||
id: "CompressHttp", | ||
comment: "", | ||
detailComment: "", | ||
const { chrome } = require("../chrome"); | ||
const {isResourceCompressed, isCompressibleResource} = require("../utils"); | ||
|
||
check: function (measures) { | ||
let compressibleResourcesSize = 0; | ||
let compressibleResourcesCompressedSize = 0; | ||
if (measures.entries.length) measures.entries.forEach(entry => { | ||
if (isCompressibleResource(entry)) { | ||
compressibleResourcesSize += entry.response.content.size; | ||
if (isResourceCompressed(entry)) { | ||
compressibleResourcesCompressedSize += entry.response.content.size; | ||
function registerCompressHttp(rulesManager) { | ||
rulesManager.registerRule({ | ||
complianceLevel: 'A', | ||
id: "CompressHttp", | ||
comment: "", | ||
detailComment: "", | ||
|
||
check: function (measures) { | ||
let compressibleResourcesSize = 0; | ||
let compressibleResourcesCompressedSize = 0; | ||
if (measures.entries.length) measures.entries.forEach(entry => { | ||
if (isCompressibleResource(entry)) { | ||
compressibleResourcesSize += entry.response.content.size; | ||
if (isResourceCompressed(entry)) { | ||
compressibleResourcesCompressedSize += entry.response.content.size; | ||
} | ||
else this.detailComment += chrome.i18n.getMessage("rule_CompressHttp_DetailComment", `${entry.request.url} ${Math.round(entry.response.content.size / 100) / 10}`) + '<br>'; | ||
} | ||
else this.detailComment += chrome.i18n.getMessage("rule_CompressHttp_DetailComment",`${entry.request.url} ${Math.round(entry.response.content.size / 100) / 10}`) + '<br>'; | ||
} | ||
}); | ||
if (compressibleResourcesSize > 0) { | ||
const compressRatio = compressibleResourcesCompressedSize / compressibleResourcesSize * 100; | ||
if (compressRatio < 95) { | ||
if (compressRatio < 90) this.complianceLevel = 'C' | ||
else this.complianceLevel = 'B'; | ||
}); | ||
if (compressibleResourcesSize > 0) { | ||
const compressRatio = compressibleResourcesCompressedSize / compressibleResourcesSize * 100; | ||
if (compressRatio < 95) { | ||
if (compressRatio < 90) this.complianceLevel = 'C' | ||
else this.complianceLevel = 'B'; | ||
} | ||
else this.complianceLevel = 'A'; | ||
this.comment = chrome.i18n.getMessage("rule_CompressHttp_Comment", String(Math.round(compressRatio * 10) / 10) + "%"); | ||
} | ||
else this.complianceLevel = 'A'; | ||
this.comment = chrome.i18n.getMessage("rule_CompressHttp_Comment", String(Math.round(compressRatio * 10) / 10) + "%"); | ||
} | ||
} | ||
}, "harReceived"); | ||
}, "harReceived"); | ||
} | ||
|
||
module.exports = { | ||
registerCompressHttp | ||
}; |
Oops, something went wrong.