While this question has been raised in the past, none of the answers provided seem to be accurate. Unfortunately, I am unable to comment on the original question or answers. Thus, following suggestions given to me, I have decided to create a new question.
How can one detect if a web page is running from a website or the local file system?
The specific issue at hand is detecting whether a user has accessed a particular page through Safari Web Archive or by entering the correct web URL.
Notably, the solutions provided in the linked question do not work with Safari webarchives. The accepted answer suggests utilizing the following check:
switch(window.location.protocol) {
case 'http:':
case 'https:':
//remote file over http or https
break;
case 'file:':
//local file
break;
default:
//some other protocol
}
However, it is noted that Safari webarchive files behave as though they are being remotely accessed on the server. Even upon testing for location protocol, it consistently returns http instead of file://
It appears that the only distinguishing factor within a safari webarchive is the mimetype of the file itself, designated as 'application/x-webarchive'. Yet, there seems to lack a dependable way to identify the mime type of the current page.
I am hopeful to come across a viable solution to differentiate between a locally stored page and one accessed remotely.