dteviot / WebToEpub

A simple Chrome (and Firefox) Extension that converts Web Novels (and other web pages) into an EPUB.
Other
669 stars 130 forks source link

WebToEpub for Safari Extensions in iOS 15 - can port from Google Chrome Web Store extensions, Firefox or Edge. #588

Open shirosora55555 opened 2 years ago

shirosora55555 commented 2 years ago

Feature Request: WebToEpub for Safari Extensions in iOS 15 - can port from Google Chrome Web Store extensions, Firefox or Edge.

Reason why I am Requesting this Feature. [1. So i can use WebToEpub in Safari in my iPad for IOS 15.

Why should it Be made for Safari Extensions in iOS 15? [1. i would gladly pay for the extension app for it. [2. Other iOS iPad Users would also likely to pay for it. [3. or placing ads for not paid version for extension app. [4. it could be benefit you if user paid or income from ads.

dteviot commented 2 years ago

@shirosora55555 I had a quick look at https://developer.apple.com/documentation/safariservices/safari_app_extensions. If I'm reading it correctly, I can't just port WebToEpub to Safari. A completely new extension would need to be be written, basically from scratch, as a iOS application. And I simply don't have the spare time to learn do that.

dteviot commented 2 years ago

@shirosora55555 Apologies, I did some more digging. According to https://lapcatsoftware.com/articles/chrome-extension.html Sounds like the truth is somewhere between us. That is, the extension might be able to work, but it requires creating a native Mac wrapper. And that requires a Mac and Mac developer skills. And it assumes Safari implements all the APIs used by WebToEpub. (Looking at https://developer.apple.com/documentation/safariservices/safari_web_extensions/assessing_your_safari_web_extension_s_browser_compatibility I don't see any obvious problems, but checking everything would take a long time.)

So, I still don't have the time for it. But if you can find someone, I have no objection to them doing the work. (Obviously, WebToEpub IS open source.)

dteviot commented 2 years ago

@shirosora55555 I asked a Mac developer friend of mine to have a try at this results:

This is the output from the converter tool:

Warning: The following keys in your manifest.json are not supported by your current version of Safari. If these are critical to your extension, you should review your code to see if you need to make changes to support Safari: icons webRequestBlocking applications browser_action incognito manifest_version downloads default_locale version webRequest name

Using Safari 14.1.2 I went ahead and created the project which builds with no complaints, And starts to work (after enabling unsigned extensions it's in the list) I tried an archiveofourown story, and the dialog appeared to generate the epub. It seemed to do something, but then:

undefined is not an object (evaluating 'browser.downloads.download') saveOnFirefox@safari-web-extension://BE21F36B-3C37-46B1-8267-0704E6BB0B9B/js/Download.js:70:33 promiseReactionJob@[native code]

presumably this is the lack of support for downloads

DicerX commented 2 years ago

I just bought a couple of iOS Safari extensions (Amplosion, Noir), and one of the things I wished for was an iOS WebtoEpub extension to add to that list. This will fit right in for when I want to consume novels without access to my PC.

Synteresis commented 2 years ago
> I believe, at the moment, it is best to wait until Safari WebExtensions updates with support for the downloads api or support for the File System Access API would help as well. My current workaround has been to create an invisible iframe and load the blob url, but that automatically downloads the file without prompting saveAs. I directly call the cleanup / revokeObjectUrl after the blob is saved and artificially return a promise without using the intermediate onDownloadStart and onChanged functions. > > Note: For the above, while finding different work arounds, I disabled some security features which I am not sure had an impact on my experience or ability to download files. After some more research, I believe the above is an incorrect approach as evident by browser-fs-access.glitch.me/. The other bug was not being able to open the popup window a second time without reloading the extension in Xcode. The first time the extension is clicked, it works like normal. The second time clicked, it no longer pops up as a new tab, but as a normal extension popup and none of the Javascript runs. I was able to fix the extension not opening a second time, but it would then open another non-tab version of the extension popup again, presumably due to the delay between window.onload in the main variable firing and the extension window popping up due to Safari doing something behind the scenes. Note for Parsers: Safari 14.1.2 does not support lookbehind on regex for some reason. Note: All of this is on Safari 14.1.2, I am tempted to update to see if some of these errors go away, but I would lose the ability to support before Safari 15. I am sure these would be easier to fix if I knew a bit more JavaScript, but I still know none. Additional Note: IOS Safari has an issue. As the IOS emulator is on IOS 15 and thus Safari 15, I am not sure at the moment if this is caused by the new browser update or the change from MacBook to iPhone. The two error messages are from different runs of the same code. ``` Fetch of URL 'https://boxnovel.com/novel/big-shots-reincarnation-sweeps-the-world/chapter-2/' failed with network error Origin safari-web-extension://eb79a289-a067-4afa-ad85-29c2c53fa8f0 is not allowed by Access-Control-Allow-Origin.. onFetchError@safari-web-extension://EB79A289-A067-4AFA-AD85-29C2C53FA8F0/js/HttpClient.js:28:40 promiseReactionJob@[native code] ``` ``` Fetch of URL 'https://boxnovel.com/novel/after-marrying-the-cold-villain/chapter-1/' failed with network error Load failed. onFetchError@safari-web-extension://32BC593D-F020-4F41-ACDB-EE03789AAD56/js/HttpClient.js:28:40 promiseReactionJob@[native code] ``` The above error is presumably due to: https://developer.apple.com/documentation/safariservices/safari_web_extensions/assessing_your_safari_web_extension_s_browser_compatibility No webRequestBlocking or webRequest on IOS Safari. Only webRequest on MacOS. Also, it seems even manually adding every single possible host pattern to the manifest, it will not grant fetch cors permissions. All this cors protection is really inhibiting the port of this extension over to Safari. does not actually grant host permissions for all urls.
dteviot commented 2 years ago

@Synteresis I've been considering a work around for the CORS. (Which I'm seeing a lot more of.) The idea would be inject code to make the fetch call into the ToC web page itself (which should be from the target site) then pass the results back to the tab holding WebToEpub.

Synteresis commented 2 years ago
I'm having problems with the current method of the popup opening, scripts executing, main detecting if it is a tab, and then the new tab This only happens after fixing the bug where it can only be clicked once and then subsequent clicks of the extension would do nothing. (Caused on Safari by the preferences access in storage being before the tab check so there is no storage to access.) I'll work on this more next week when I have time. Learning something new is exhausting and time consuming. Personal Notes: Inject fetch into webpage, vulnerable to attacks? Background script fetch bypasses CORS with proper host permissions. Check for nested iframes? webRequest header workaround or page injection method. fetch vs xml for Safari? Look at the polyfills. Look at browser fs api. Setup on Windows laptop. Xcode annoying to work in. Inject and Return https://stackoverflow.com/questions/41577988/chrome-tabs-executescript-how-to-get-result-of-content-script CORS https://stackoverflow.com/questions/47356375/firefox-fetch-api-how-to-omit-the-origin-header-in-the-request https://stackoverflow.com/questions/20937287/how-to-intercept-a-web-request https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/executeScript#browser_compatibility https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage https://developer.apple.com/documentation/safariservices/safari_web_extensions/assessing_your_safari_web_extension_s_browser_compatibility https://www.chromium.org/Home/chromium-security/extension-content-script-fetches https://developer.chrome.com/docs/extensions/mv3/xhr/ https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts https://stackoverflow.com/questions/40248467/chrome-extension-accessing-a-cross-origin-iframe-within-background-html https://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy https://stackoverflow.com/questions/53024760/cors-and-web-extensions Unreliable window.onload on Safari https://stackoverflow.com/questions/34677628/load-event-not-fired-on-safari-when-reloading-page DOMContentLoad? https://stackoverflow.com/questions/7168362/run-script-each-time-chrome-extension-icon-clicked https://developer.chrome.com/extensions/overview#arch