-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
106c845
commit da1d07d
Showing
11 changed files
with
564 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import fs from 'fs' | ||
import os from 'os' | ||
import path from 'path' | ||
import {type Compiler} from 'webpack' | ||
import * as messages from '../browsers-lib/messages' | ||
import {PluginInterface} from '../browsers-types' | ||
import {DevOptions} from '../../module' | ||
import {launchSafari} from './safari/launch-safari' | ||
import { | ||
checkXcodeCommandLineTools, | ||
ensureXcodeDirectory, | ||
checkSafariWebExtensionConverter | ||
} from './xcode/setup-xcode' | ||
import {generateSafariProject} from './xcode/generate-project' | ||
|
||
export class RunSafariPlugin { | ||
public readonly extension: string | string[] | ||
public readonly browser: DevOptions['browser'] | ||
public readonly browserFlags?: string[] | ||
public readonly profile?: string | ||
public readonly preferences?: Record<string, any> | ||
public readonly startingUrl?: string | ||
|
||
constructor(options: PluginInterface) { | ||
this.extension = options.extension | ||
this.browser = options.browser | ||
this.browserFlags = options.browserFlags || [] | ||
this.profile = options.profile | ||
this.preferences = options.preferences | ||
this.startingUrl = options.startingUrl | ||
} | ||
|
||
private isMacOS(): boolean { | ||
return os.platform() === 'darwin' | ||
} | ||
|
||
apply(compiler: Compiler): void { | ||
compiler.hooks.done.tapAsync('RunSafariPlugin', (stats, done) => { | ||
if (stats.hasErrors()) { | ||
console.error('Build failed. Aborting Safari launch.') | ||
done() | ||
return | ||
} | ||
|
||
try { | ||
// Ensure the environment is properly configured for Safari extension development | ||
checkXcodeCommandLineTools() | ||
// const xcodePath = ensureXcodeDirectory(process.cwd()) | ||
const xcodePath = compiler.options.output.path || '' | ||
checkSafariWebExtensionConverter() | ||
|
||
console.log( | ||
`Xcode configuration verified. Using directory: ${xcodePath}` | ||
) | ||
|
||
// Check if the xcode folder is populated with the expected project | ||
const outputPath = path.join( | ||
xcodePath, | ||
'printfriendly-safari.xcodeproj' | ||
) | ||
if (!fs.existsSync(outputPath)) { | ||
console.log( | ||
`'xcode' folder is empty. Generating Xcode project for Safari Web Extension...` | ||
) | ||
const userExtension = Array.isArray(this.extension) | ||
? this.extension[0] | ||
: this.extension | ||
// AppName is the parsed Manifest.json name | ||
const manifestJson = JSON.parse( | ||
fs.readFileSync(path.join(userExtension, 'manifest.json'), 'utf8') | ||
) | ||
// Ensure appname is valid | ||
const appName = manifestJson.name | ||
// .replace(/[^a-zA-Z0-9]/g, '') | ||
|
||
// i.e com.example.myextension | ||
const identifier = manifestJson.homepage_url | ||
? manifestJson.homepage_url.replace(/[^a-zA-Z0-9]/g, '') | ||
: 'org.extensionjs.extension' | ||
|
||
generateSafariProject(userExtension, xcodePath, appName, identifier) | ||
console.log(`Xcode project successfully created at: ${outputPath}`) | ||
} else { | ||
console.log(`Existing Xcode project found at: ${outputPath}`) | ||
} | ||
|
||
// Launch Safari using the extracted logic | ||
launchSafari({ | ||
startingUrl: this.startingUrl, | ||
isMacOS: this.isMacOS(), | ||
browser: this.browser | ||
}) | ||
} catch (error: any) { | ||
console.error(error.message) | ||
process.exit(1) | ||
} | ||
|
||
done() | ||
}) | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
programs/develop/plugin-browsers/run-safari/safari/browser-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import {type PluginInterface} from '../../browsers-types' | ||
import {createProfile} from '../create-profile' | ||
|
||
export function browserConfig(configOptions: PluginInterface) { | ||
const extensionsToLoad = Array.isArray(configOptions.extension) | ||
? configOptions.extension | ||
: [configOptions.extension] | ||
|
||
const userProfilePath = createProfile( | ||
configOptions.browser, | ||
configOptions.profile, | ||
configOptions.preferences | ||
) | ||
|
||
// Flags set by default: | ||
// https://github.com/GoogleChrome/chrome-launcher/blob/master/src/flags.ts | ||
// Added useful flags for tooling: | ||
// Ref: https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md | ||
return [ | ||
`--load-extension=${extensionsToLoad.join()}`, | ||
`--user-data-dir=${userProfilePath}`, | ||
// Disable Chrome's native first run experience. | ||
'--no-first-run', | ||
// Disables client-side phishing detection | ||
'--disable-client-side-phishing-detection', | ||
// Disable some built-in extensions that aren't affected by '--disable-extensions' | ||
'--disable-component-extensions-with-background-pages', | ||
// Disable installation of default apps | ||
'--disable-default-apps', | ||
// Disables the Discover feed on NTP | ||
'--disable-features=InterestFeedContentSuggestions', | ||
// Disables Chrome translation, both the manual option and the popup prompt when a | ||
// page with differing language is detected. | ||
'--disable-features=Translate', | ||
// Hide scrollbars from screenshots. | ||
'--hide-scrollbars', | ||
// Mute any audio | ||
'--mute-audio', | ||
// Disable the default browser check, do not prompt to set it as such | ||
'--no-default-browser-check', | ||
// Avoids blue bubble "user education" nudges | ||
// (eg., "… give your browser a new look", Memory Saver) | ||
'--ash-no-nudges', | ||
// Disable the 2023+ search engine choice screen | ||
'--disable-search-engine-choice-screen', | ||
// Avoid the startup dialog for | ||
// `Do you want the application “Chromium.app” to accept incoming network connections?`. | ||
// Also disables the Chrome Media Router which creates background networking activity | ||
// to discover cast targets. | ||
// A superset of disabling DialMediaRouteProvider. | ||
'--disable-features=MediaRoute', | ||
// Use mock keychain on Mac to prevent the blocking permissions dialog about | ||
// "Chrome wants to use your confidential information stored in your keychain" | ||
'--use-mock-keychain', | ||
// Disable various background network services, including extension updating, | ||
// safe browsing service, upgrade detector, translate, UMA | ||
'--disable-background-networking', | ||
// Disable crashdump collection (reporting is already disabled in Chromium) | ||
'--disable-breakpad', | ||
// Don't update the browser 'components' listed at chrome://components/ | ||
'--disable-component-update', | ||
// Disables Domain Reliability Monitoring, which tracks whether the browser | ||
// has difficulty contacting Google-owned sites and uploads reports to Google. | ||
'--disable-domain-reliability', | ||
// Disables autofill server communication. This feature isn't disabled via other 'parent' flags. | ||
'--disable-features=AutofillServerCommunicatio', | ||
'--disable-features=CertificateTransparencyComponentUpdate', | ||
// Disable syncing to a Google account | ||
'--disable-sync', | ||
// Used for turning on Breakpad crash reporting in a debug environment where crash | ||
// reporting is typically compiled but disabled. | ||
// Disable the Chrome Optimization Guide and networking with its service API | ||
'--disable-features=OptimizationHints', | ||
// A weaker form of disabling the MediaRouter feature. See that flag's details. | ||
'--disable-features=DialMediaRouteProvider', | ||
// Don't send hyperlink auditing pings | ||
'--no-pings', | ||
// Ensure the side panel is visible. This is used for testing the side panel feature. | ||
'--enable-features=SidePanelUpdates', | ||
|
||
// Flags to pass to Chrome | ||
// Any of http://peter.sh/experiments/chromium-command-line-switches/ | ||
...(configOptions.browserFlags || []) | ||
] | ||
} |
Oops, something went wrong.