Compare commits

..
2 Commits
8 changed files with 230 additions and 9 deletions
+1 -1
View File
@@ -1 +1 @@
0.0.66
0.0.68
+2 -3
View File
@@ -254,13 +254,12 @@ cmd_start() {
fi
fi
# Build first
# Build first (use build.sh for proper version embedding)
echo "[browser] Building..."
if ! make -s 2>/dev/null; then
if ! ./build.sh 2>/dev/null; then
echo "[browser] Build failed!" >&2
return 1
fi
echo "[browser] Build OK."
# Launch fully detached:
# setsid — new session, detached from controlling terminal
+41 -3
View File
@@ -35,7 +35,7 @@ static const char *guess_mime(const char *path) {
if (g_ascii_strcasecmp(ext, ".js") == 0)
return "application/javascript; charset=utf-8";
if (g_ascii_strcasecmp(ext, ".mjs") == 0)
return "application/javascript; charset=utf-8";
return "text/javascript; charset=utf-8";
if (g_ascii_strcasecmp(ext, ".json") == 0)
return "application/json";
if (g_ascii_strcasecmp(ext, ".svg") == 0)
@@ -88,14 +88,50 @@ static void on_local_scheme(WebKitURISchemeRequest *request, gpointer user_data)
/* Strip "local://" prefix to get the file path. The URI is
* local:///absolute/path, so we skip 8 characters ("local://")
* and the result is /absolute/path. */
const char *path = uri + 8;
if (path == NULL || path[0] == '\0') {
const char *path_start = uri + 8;
if (path_start == NULL || path_start[0] == '\0') {
g_printerr("[local-scheme] Empty path in URI: %s\n", uri);
webkit_uri_scheme_request_finish_error(request, g_error_new_literal(
g_quark_from_static_string("local-scheme"), 1, "Empty path"));
return;
}
/* Strip query parameters (?...) from the path. Web pages and
* SharedWorkers may append ?v=... or other cache-busting params. */
char *path = g_strdup(path_start);
char *qmark = strchr(path, '?');
if (qmark) *qmark = '\0';
/* Resolve root-relative paths against the requesting page's directory.
* If the path is an absolute filesystem path (e.g. /home/user/...),
* use it as-is. If it's a root-relative path (e.g. /nostr-login-lite/...)
* that doesn't exist, try resolving it relative to the page's directory. */
if (path[0] == '/' && !g_file_test(path, G_FILE_TEST_EXISTS)) {
WebKitWebView *wv = webkit_uri_scheme_request_get_web_view(request);
if (wv) {
const char *page_uri = webkit_web_view_get_uri(wv);
if (page_uri && g_str_has_prefix(page_uri, "local://")) {
/* Get the page's directory. */
const char *page_path = page_uri + 8;
char *page_dir = g_strdup(page_path);
char *last_slash = strrchr(page_dir, '/');
if (last_slash) {
*(last_slash + 1) = '\0';
char *resolved = g_strconcat(page_dir, path + 1, NULL);
if (g_file_test(resolved, G_FILE_TEST_EXISTS)) {
g_print("[local-scheme] Resolved root-relative %s -> %s\n",
path, resolved);
g_free(path);
path = resolved;
} else {
g_free(resolved);
}
}
g_free(page_dir);
}
}
}
/* Read the file. */
gsize length = 0;
char *content = NULL;
@@ -104,6 +140,7 @@ static void on_local_scheme(WebKitURISchemeRequest *request, gpointer user_data)
if (!g_file_get_contents(path, &content, &length, &error)) {
g_printerr("[local-scheme] Failed to read %s: %s\n", path,
error ? error->message : "unknown error");
g_free(path);
if (error) g_error_free(error);
webkit_uri_scheme_request_finish_error(request, g_error_new_literal(
g_quark_from_static_string("local-scheme"), 2, "File not found"));
@@ -114,6 +151,7 @@ static void on_local_scheme(WebKitURISchemeRequest *request, gpointer user_data)
const char *mime_type = guess_mime(path);
g_print("[local-scheme] Serving %s (%s, %lu bytes)\n", path, mime_type,
(unsigned long)length);
g_free(path);
/* Wrap the content in a GInputStream. g_memory_input_stream_new_from_data
* takes ownership of the data via the GDestroyNotify callback. */
+2 -2
View File
@@ -11,9 +11,9 @@
#ifndef SOVEREIGN_BROWSER_VERSION_H
#define SOVEREIGN_BROWSER_VERSION_H
#define SB_VERSION "v0.0.66"
#define SB_VERSION "v0.0.68"
#define SB_VERSION_MAJOR 0
#define SB_VERSION_MINOR 0
#define SB_VERSION_PATCH 66
#define SB_VERSION_PATCH 68
#endif /* SOVEREIGN_BROWSER_VERSION_H */
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SharedWorker importScripts Test</title>
<style>
body { font-family: sans-serif; background: #1a1a2e; color: #eee; padding: 40px; }
h1 { margin-bottom: 10px; }
.pass { color: #0f0; }
.fail { color: #f00; }
.info { color: #ff0; }
#output { background: #16213e; padding: 16px; border-radius: 8px; margin-top: 20px; font-family: monospace; white-space: pre-wrap; }
</style>
</head>
<body>
<h1>🔄 SharedWorker importScripts Test</h1>
<p>Tests whether <code>importScripts()</code> works inside a SharedWorker loaded from <code>local://</code>.</p>
<div id="output">Running tests...</div>
<script>
var output = document.getElementById('output');
function log(msg, cls) {
output.innerHTML += '<span class="' + (cls || '') + '">' + msg + '</span>\n';
}
log('=== importScripts Test ===\n', 'info');
try {
var worker = new SharedWorker('shared-worker-import-test.js');
log('✓ SharedWorker constructor succeeded', 'pass');
worker.port.onmessage = function(e) {
log('✓ Received: ' + e.data, 'pass');
};
worker.port.onerror = function(e) {
log('✗ Worker error: ' + (e.message || 'unknown'), 'fail');
};
worker.port.postMessage('ping');
setTimeout(function() {
log('\n--- Done ---', 'info');
}, 3000);
} catch (e) {
log('✗ SharedWorker constructor threw: ' + e.message, 'fail');
}
</script>
</body>
</html>
@@ -0,0 +1,31 @@
/**
* SharedWorker test for importScripts() on local://.
* Tests whether importScripts() can load scripts from the local:// scheme.
*/
console.log('[Import-Test] Worker script executing');
console.log('[Import-Test] self.location.href:', self.location.href);
console.log('[Import-Test] self.location.origin:', self.location.origin);
// Try importScripts with a relative path
try {
importScripts('./shared-worker-test.js');
console.log('[Import-Test] importScripts succeeded');
} catch (e) {
console.log('[Import-Test] importScripts FAILED:', e.message);
}
self.onconnect = function(e) {
var port = e.ports[0];
port.postMessage('worker_ready');
port.onmessage = function(e) {
if (e.data === 'ping') {
port.postMessage('pong');
} else if (e.data === 'get_info') {
port.postMessage(JSON.stringify({
href: self.location.href,
origin: self.location.origin,
protocol: self.location.protocol
}));
}
};
};
+71
View File
@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SharedWorker Test</title>
<style>
body { font-family: sans-serif; background: #1a1a2e; color: #eee; padding: 40px; }
h1 { margin-bottom: 10px; }
.pass { color: #0f0; }
.fail { color: #f00; }
.info { color: #ff0; }
#output { background: #16213e; padding: 16px; border-radius: 8px; margin-top: 20px; font-family: monospace; white-space: pre-wrap; }
</style>
</head>
<body>
<h1>🔄 SharedWorker Test</h1>
<p>Tests whether <code>SharedWorker</code> works when loaded from a <code>local://</code> URI.</p>
<div id="output">Running tests...</div>
<script>
var output = document.getElementById('output');
function log(msg, cls) {
output.innerHTML += '<span class="' + (cls || '') + '">' + msg + '</span>\n';
}
log('=== SharedWorker Test ===\n', 'info');
// Test 1: Is SharedWorker supported?
if (typeof SharedWorker !== 'undefined') {
log('✓ SharedWorker is supported by this browser', 'pass');
} else {
log('✗ SharedWorker is NOT supported by this browser', 'fail');
}
// Test 2: Try to create a SharedWorker
try {
var worker = new SharedWorker('shared-worker-test.js');
log('✓ SharedWorker constructor succeeded', 'pass');
worker.port.onmessage = function(e) {
log('✓ Received message from worker: ' + e.data, 'pass');
};
worker.port.onerror = function(e) {
log('✗ Worker error: ' + (e.message || 'unknown'), 'fail');
};
// Send a ping
worker.port.postMessage('ping');
// Timeout after 3 seconds
setTimeout(function() {
log('\n--- Timeout reached ---', 'info');
log('If you see "Received message from worker" above, SharedWorker works.', 'info');
log('If not, SharedWorker failed to load or communicate.', 'info');
}, 3000);
} catch (e) {
log('✗ SharedWorker constructor threw: ' + e.message, 'fail');
}
// Test 3: What is our current origin?
log('\n=== Origin Info ===', 'info');
log('location.href: ' + location.href, 'info');
log('location.origin: ' + (location.origin || 'null'), 'info');
log('location.protocol: ' + location.protocol, 'info');
</script>
</body>
</html>
+29
View File
@@ -0,0 +1,29 @@
/**
* Minimal SharedWorker test script.
* Responds to 'ping' with 'pong' and reports its own URL and origin.
*/
console.log('[SharedWorker-Test] Worker script executing...');
console.log('[SharedWorker-Test] self.location.href:', self.location.href);
console.log('[SharedWorker-Test] self.location.origin:', self.location.origin);
console.log('[SharedWorker-Test] self.location.protocol:', self.location.protocol);
self.onconnect = function(e) {
var port = e.ports[0];
console.log('[SharedWorker-Test] Connected from port');
port.postMessage('worker_ready');
port.onmessage = function(e) {
console.log('[SharedWorker-Test] Received:', e.data);
if (e.data === 'ping') {
port.postMessage('pong');
} else if (e.data === 'get_info') {
port.postMessage(JSON.stringify({
href: self.location.href,
origin: self.location.origin,
protocol: self.location.protocol
}));
}
};
};