GithubHelp home page GithubHelp logo

Comments (5)

 avatar commented on June 15, 2024

Good point, we did not test with restrictive CSP yet. Thank you for bringing that up. Of course we need to support that.

Current situation
We have some voodoo for <script>s in place:

  • we let a new DOM-object parse the HTML from the inject setting
  • with any <script> in there (which will be inactive due to being inserted with .innerHTML) we extract it and add it one by one (to the end of the <body>)

Here's the relevant section

function injectTrackingObject(trackingObjectId, trackingObjectSettings) {
if (typeof trackingObjectSettings.inject !== "undefined") {
// <script>s inserted via innerHTML won't be executed
// https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML
// Let the DOM parse our inject-HTML...
var pseudo = document.createElement('span')
pseudo.innerHTML = trackingObjectSettings.inject
// ...and insert <script>s manually
var pseudoScripts = pseudo.querySelectorAll('script'),
_script
for (var _i = 0; _i < pseudoScripts.length; _i++) {
_script = document.createElement('script')
_script.textContent = pseudoScripts[_i].textContent
document.body.appendChild(_script)
pseudo.removeChild(pseudoScripts[_i]) // remove from pseudo
}
// append the rest of pseudo
document.body.appendChild(pseudo)
// keep track what we injected
injectedTrackingObjects.push(trackingObjectId)
}
}

Found a problem
I think I just forgot to copy all of the <script>'s attributes to the newly inserted one! So e.g. any src= would not be transferred!
If we do that correctly, I feel we should be ok as we would do then exactly as many tracking objects inject itself:

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

Tests
I'd like to add that also to the automated tests.
Are you using Content-Security-Policy: script-src 'self'?
Thing is that this also affects the example themes: you cannot use onclick=... with that ;)

reSt docs
Oh, I would be very happy to have the docs .rst'ed and would gladly switch to it:) I just don't have any experience with it yet and feared that our multi-branch-approach would be a bit difiicult to set up with https://docs.typo3.org/ - it would be great if you could get us started with that. Thank you, Sebastian!

from extension-cookieman.

 avatar commented on June 15, 2024

I pushed a JavaScript change that should fix inclusion of script tags.

Could you please review this change in cookieman[.min].js?

b595ae1

from extension-cookieman.

sebkln avatar sebkln commented on June 15, 2024

Great! The external JavaScript sources of my Matomo demo are now injected in the HTML and recognized.

On some pages I now get error messages in the browser console that _paq.push() was used but Matomo tracker was not initialized before the matomo.js file was loaded. But this is a different issue that needs to be fixed by myself.

from extension-cookieman.

 avatar commented on June 15, 2024

On some pages I now get error messages in the browser console that _paq.push() was used but Matomo tracker was not initialized before the matomo.js file was loaded. But this is a different issue that needs to be fixed by myself.

Normally you would attach a function to the script like <script onload="callAllPaq_s()"...> but as I just learned inline JavaScript wouldn't work with CSP: script-src.
It would be nice if cookieman could provide an event so that you could do:

cookieman.TrackingObjects.Matomo.injects.scripts[0].onload = function() { _pag.push() }

That would be possible and not too hard to implement.

from extension-cookieman.

 avatar commented on June 15, 2024

I changed the API a bit from my initial idea: https://github.com/dmind-gmbh/extension-cookieman#cookiemanonscriptloadedstring-trackingobjectkey-int-scriptid-function-callback-void

Does that fit your use case?

from extension-cookieman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.