Custom HTML Prompt refuses to load a local image

I have some HTML code that displays a local image file. It works perfectly in a browser. But when I try to execute it in a KM Custom HTML Prompt it fails with the error, "Not allowed to load local resource." followed by "file:///......JPG".

There has to be a fix for this. Surely KM HTML prompts are not restricted from opening local files.

Keyboard Maestro explicitly allows any file references. I just tested it and this worked fine:

<img src="/tmp/example.svg" alt="example">

So it may be that the system is blocking the request, depending on where the file is. You could try allowing Full Disk Access to Keyboard Maestro Engine.

Otherwise, you'll need to post an example that isn't working, perhaps you are doing something different that is the issue.

1 Like

Thanks for the suggestion. Actually the problem is with external disk access. The failure was on a removable device. It works fine with a file in my home directory. (I didn't get the typical MacOS popup grousing about trying to access a removable device.)

I think the problem is that the browser is not, by design, allowed to access the local file system unless it's on the same volume.

I tried:

	<img src="/Volumes/NO%20NAME/bu-10.jpg" width="800" height="531"><br>
	<img src="/Users/myuser/Desktop/untitled%20folder/bu-10.jpg" width="800" height="531">

The first (an SD card) would not display but the second was fine. (You'd want to encode the space in your file path, BTW.)

Because Peter is referencing his local volume he wouldn't see the problem.

1 Like

@peternlewis OK... Even though KM has permission to access remote files, that permission is not being extended to custom HTML windows.

Here is the KM entry in Security & Privacy -> Privacy -> Files and Folders:
image

Here is the code:

<!doctype html>
<html>
<head>
	<style>
		.image {
			width: 100px;
			height: auto;
		}
	</style>
</head>
<body>
	<img class="image" src="/Volumes/IMAGES/Cozumel%202021/test/V1O90001.JPG">
	<img class="image" src="/Users/jjh/_COZ0001.JPG">
</body>
</html>

Here is the output in Chrome:
image

Here is the KM Custom HTML Prompt window:
image

Here is the KM console log:

Exactly. Although the "by design" is normally handled with the Files & Folders permission. In the example above Chrome, which has that permission, can access the file.

(It's usually happy with unencoded paths, but OK, I'll add the filter action. :wink: )

The Custom HTML Prompt is built on WebKit which (I'm guessing) is the stumbling block.

1 Like

@mrpasini Good insight. Safari could not open the file either. Safari --> Develop --> Disable Local File Restrictions did the trick. You can't get access to that for a KM Custom HTML window though. I'm loathe to start poking around in KM plist files, but doubtless there is a way to turn on access. I wonder if there is already a WebKit defaults setting that will enable it.

I would just move stuff onto the local disk, except I am trying to reach into a several-terabyte archive.

I don't see any way to specify that in WKWebView. There might be a way, but it doesn't appear to be documented anywhere.

An obvious, if not ideal, solution is to have Keyboard Maestro copy the desired file to somewhere else and the web view access it from there.

@peternlewis Thanks for looking. If I happen to run across a discussion of it somewhere I'll let you know. In the mean time that is the workaround I'm using. As you say, not ideal, but also not the ugliest workaround ever. It's great if awkward for MB scale stuff, but not so hot for GB stuff.

If I decide it's worth the effort the better solution might be to use Apache to serve the files.

BTW, I'm having a lot of fun playing with web-like apps in Custom HTML Windows. The fact that the user can interact directly with both the server and client opens up all sorts of possibilities. If/when I get a framework that seems stable and generally useful I'll post.

1 Like