added http error detection.

This commit is contained in:
dwebmm 2025-01-21 02:39:08 -06:00
parent 7e9107f9f2
commit 05c909787a
2 changed files with 86 additions and 147 deletions

View file

@ -191,6 +191,17 @@
</div> </div>
</div> </div>
<div id="blockedModal" class="modal blocked-modal">
<div class="modal-content">
<h2>⚠️ Content Blocked</h2>
<p>This content cannot be displayed due to security restrictions.</p>
<div class="blocked-modal-buttons">
<button id="blockedRetryBtn" class="blocked-retry-btn">Try Another Site</button>
<button id="blockedOpenBtn" class="blocked-open-btn">Open in New Tab</button>
</div>
</div>
</div>
<main> <main>
<iframe <iframe
id="contentFrame" id="contentFrame"
@ -256,146 +267,73 @@
// Wait for the page to load then focus // Wait for the page to load then focus
frame.onload = () => { frame.onload = () => {
// Check if we landed on a blocked/error page
try {
// Get the actual URL from the iframe
const currentUrl = frame.contentWindow.location.href;
console.log("Current URL:", currentUrl); // Debug log
// Check if it's an HTTP URL
if (currentUrl.startsWith('http:')) {
console.log("HTTP URL detected, showing modal"); // Debug log
const httpModal = document.createElement('div');
httpModal.className = 'modal http-modal show';
httpModal.innerHTML = `
<div class="modal-content">
<h2>⚠️ HTTP Content</h2>
<p>This website uses HTTP and cannot be displayed in the frame for security reasons.</p>
<div class="http-modal-buttons">
<button class="http-open-btn">Open in New Tab</button>
<button class="http-skip-btn">Skip This Site</button>
</div>
</div>
`;
document.body.appendChild(httpModal);
// Handle button clicks
const openBtn = httpModal.querySelector('.http-open-btn');
const skipBtn = httpModal.querySelector('.http-skip-btn');
openBtn.addEventListener('click', () => {
console.log("Opening in new tab:", currentUrl); // Debug log
window.open(currentUrl, '_blank');
httpModal.remove();
fumble();
});
skipBtn.addEventListener('click', () => {
console.log("Skipping site"); // Debug log
httpModal.remove();
fumble();
});
return;
}
// Check for error pages
const title = frame.contentWindow.document.title.toLowerCase();
if (
title.includes("blocked") ||
title.includes("error") ||
title.includes("refused") ||
title.includes("cannot") ||
title.includes("denied")
) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> parent of 97f3a78 (Reverted back to 4cd4110 before changes were made to monitoring. Trying)
fumble();
return;
}
frame.focus();
try { try {
frame.contentWindow.focus(); const title = frame.contentWindow.document.title.toLowerCase();
if (
title.includes("blocked") ||
title.includes("error") ||
title.includes("refused") ||
title.includes("cannot") ||
title.includes("denied")
) {
fumble();
return;
}
frame.focus();
try {
frame.contentWindow.focus();
} catch (e) {
// Ignore cross-origin errors
}
} catch (e) { } catch (e) {
// Ignore cross-origin errors // Only show modal for mixed content errors
} if (e.toString().includes("mixed active content")) {
} catch (e) { const blockedModal = document.getElementById('blockedModal');
console.log("Error in onload:", e); // Debug log const retryBtn = document.getElementById('blockedRetryBtn');
// If we can't access the URL due to CORS, try using the src attribute const openBtn = document.getElementById('blockedOpenBtn');
if (frame.src.startsWith('http:')) {
console.log("HTTP URL detected from src attribute"); // Debug log blockedModal.classList.add('show');
const httpUrl = frame.src;
const httpModal = document.createElement('div'); retryBtn.onclick = () => {
httpModal.className = 'modal http-modal show'; blockedModal.classList.remove('show');
httpModal.innerHTML = ` fumble();
<div class="modal-content"> };
<h2>⚠️ HTTP Content</h2>
<p>This website uses HTTP and cannot be displayed in the frame for security reasons.</p> openBtn.onclick = () => {
<div class="http-modal-buttons"> window.open(frame.src, '_blank');
<button class="http-open-btn">Open in New Tab</button> blockedModal.classList.remove('show');
<button class="http-skip-btn">Skip This Site</button> fumble();
</div> };
</div> return;
`; }
document.body.appendChild(httpModal); // For other errors, just try another site
<<<<<<< HEAD
=======
// Show blocked content modal
const blockedModal = document.getElementById('blockedModal');
const retryBtn = document.getElementById('blockedRetryBtn');
const openBtn = document.getElementById('blockedOpenBtn');
blockedModal.classList.add('show');
retryBtn.onclick = () => {
blockedModal.classList.remove('show');
fumble(); fumble();
};
openBtn.onclick = () => {
window.open(frame.src, '_blank');
blockedModal.classList.remove('show');
fumble();
};
=======
// Try again if we hit an error page
fumble();
>>>>>>> b6825be (Revert "Reverted back to 4cd4110 before changes were made to monitoring. Trying")
return;
}
} catch (e) {
// Can't access title due to CORS - assume page is OK
}
>>>>>>> 495bda9 (Reverted back to 4cd4110 before changes were made to monitoring. Trying)
=======
>>>>>>> parent of 97f3a78 (Reverted back to 4cd4110 before changes were made to monitoring. Trying)
// Handle button clicks
const openBtn = httpModal.querySelector('.http-open-btn');
const skipBtn = httpModal.querySelector('.http-skip-btn');
openBtn.addEventListener('click', () => {
console.log("Opening in new tab:", httpUrl); // Debug log
window.open(httpUrl, '_blank');
httpModal.remove();
fumble();
});
skipBtn.addEventListener('click', () => {
console.log("Skipping site"); // Debug log
httpModal.remove();
fumble();
});
return;
} }
}; };
// Handle load errors // Also update error handler to check for mixed content
frame.onerror = () => { frame.onerror = (error) => {
fumble(); // Try again if loading fails if (error && error.toString().includes("mixed active content")) {
const blockedModal = document.getElementById('blockedModal');
const retryBtn = document.getElementById('blockedRetryBtn');
const openBtn = document.getElementById('blockedOpenBtn');
blockedModal.classList.add('show');
retryBtn.onclick = () => {
blockedModal.classList.remove('show');
fumble();
};
openBtn.onclick = () => {
window.open(frame.src, '_blank');
blockedModal.classList.remove('show');
fumble();
};
} else {
fumble(); // For other errors, just try another site
}
}; };
}; };

View file

@ -909,20 +909,19 @@ main:hover .floating-button {
.full-license a:hover { .full-license a:hover {
text-decoration: underline; text-decoration: underline;
<<<<<<< HEAD
} }
.http-modal .modal-content { .blocked-modal .modal-content {
max-width: 400px; max-width: 400px;
} }
.http-modal-buttons { .blocked-modal-buttons {
display: flex; display: flex;
gap: 10px; gap: 10px;
margin-top: 20px; margin-top: 20px;
} }
.http-open-btn, .http-skip-btn { .blocked-retry-btn, .blocked-open-btn {
flex: 1; flex: 1;
padding: 12px; padding: 12px;
border: none; border: none;
@ -933,31 +932,33 @@ main:hover .floating-button {
transition: background-color 0.3s ease; transition: background-color 0.3s ease;
} }
.http-open-btn { .blocked-retry-btn {
background-color: #ff4500; background-color: #ff4500;
color: white; color: white;
} }
.dark-mode .http-open-btn { .dark-mode .blocked-retry-btn {
background-color: #ff6b4a; background-color: #ff6b4a;
} }
.http-open-btn:hover { .blocked-retry-btn:hover {
background-color: #ff5722; background-color: #ff5722;
} }
.http-skip-btn { .blocked-open-btn {
background-color: #f0f0f0; background-color: #f0f0f0;
color: #333; color: #333;
} }
.dark-mode .http-skip-btn { .dark-mode .blocked-open-btn {
background-color: #2a2a2a; background-color: #2a2a2a;
color: #fff; color: #fff;
} }
.http-skip-btn:hover { .blocked-open-btn:hover {
background-color: #e0e0e0; background-color: #e0e0e0;
======= }
>>>>>>> b6825be (Revert "Reverted back to 4cd4110 before changes were made to monitoring. Trying")
} .dark-mode .blocked-open-btn:hover {
background-color: #333;
}