ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
315 stars 35 forks source link

Content Security Policy Issue? #702

Open runningcheese opened 1 month ago

runningcheese commented 1 month ago

As We know. We can use ContextSearch-web-ext to execute bookmarklets, but on some websites with Content Security Policy enabled, the bookmarklets don't work properly. Is there an option like "scriptsUseBlobs": true to remove the website's CSP restrictions?

Anyway, The extension shortkeys will execute bookmarklets properly. But ContextSearch-web-ext not. Thank you in advance. @ssborbis

ssborbis commented 1 month ago

Do you have an example website i can test?

runningcheese commented 1 month ago

Use this code on https://github.com/.

javascript:(function (){ var frame = document.createElement('iframe'); frame.setAttribute('id', 'sidebarView'); var href = 'https://kimi.moonshot.cn/'; frame.src = href; frame.style.position = 'fixed'; frame.style.top = '-1px'; frame.style.right = '0%'; frame.style.height = '100%'; frame.style.width = '450px'; frame.style.border = '1px solid #bbb'; frame.style.background = '#fff'; frame.style.zIndex = '100000'; document.body.appendChild(frame); var resizeHandle = document.createElement('div'); resizeHandle.id = 'resize-handle'; var handleStyles = { 'width': '10px', 'height': '100%', 'position': 'fixed', 'top': '0', 'right': '450px', 'cursor': 'ew-resize', 'z-index': '100001', 'background-color': 'rgba(0,0,0,0)' }; for (var style in handleStyles) { resizeHandle.style.setProperty(style, handleStyles[style]); } document.body.appendChild(resizeHandle); var isResizing = false; var lastDownX = 0; resizeHandle.addEventListener('mousedown', function (e) { isResizing = true; lastDownX = e.clientX; }); document.addEventListener('mousemove', function (e) { if (!isResizing) return; var offsetRight = document.body.offsetWidth - (e.clientX - document.body.offsetLeft); frame.style.width = offsetRight + 'px'; resizeHandle.style.right = offsetRight + 'px'; updateCloseButtonPosition(); }); document.addEventListener('mouseup', function () { isResizing = false; }); var closeButton = document.createElement('button'); closeButton.setAttribute('id', 'sidebarClose'); closeButton.onclick = () => { document.querySelectorAll('#sidebarView,#sidebarClose,#resize-handle').forEach(function (i) { i.parentElement.removeChild(i); }); }; var closeButtonStyles = { 'all': 'reset', 'position': 'fixed', 'z-index': '999999', 'top': '27px', 'width': '28px', 'height': '28px', 'border-radius': '50%', 'border': '2px solid #bbb', 'background-color': '#eee', 'text-align': 'center', 'line-height': '24px', 'font-size': '16px' }; for (var style in closeButtonStyles) { closeButton.style.setProperty(style, closeButtonStyles[style]); } closeButton.innerText = '✕'; document.body.appendChild(closeButton); function updateCloseButtonPosition() { var iframeWidth = frame.offsetWidth; var buttonWidth = closeButton.offsetWidth; closeButton.style.right = (iframeWidth / 2 - buttonWidth / 2) + 'px'; } updateCloseButtonPosition();})();

This code is a bookmarklet, It can run on regular webpages, but not on CSP pages like sspai.com.

However, Using the shortkeys extension allows bypassing CSP restrictions, This is what I want.

ssborbis commented 1 month ago

I can't load that website either. Maybe it's my ISP or a regional issue, although I've tried with a VPN too.

runningcheese commented 1 month ago

I can't load that website either. Maybe it's my ISP or a regional issue, although I've tried with a VPN too.

You can also try github.com, which also has CSP restrictions. @ssborbis