Contents

Application

This page gives an overview of the Molybden application. Describes how to configure, initialize, and terminate it.

Overview

Molybden application is based on Chromium and inherits its multi-process architecture.

When you run the application executable file, the launch() function defined in the src-cpp/src/main.cc file of the generated project is called.

In this function you can configure and initialize the application. The launch() function is called only once during the application lifetime.

Initializing application

To initialize the application with the default options, use the following approach:

#include "molybden.hpp"

using namespace molybden;

void launch() {
  App::init([](std::shared_ptr<App> app) {
    // Work with the app here.  
  });
}

Important: Application must be initialized only once. An attempt to initialize it more than once will lead to undefined behavior.

Application options

You can configure the application with custom options. To do this, use the App::init() function with the AppOptions parameter:

#include "molybden.hpp"

using namespace molybden;

void launch() {
  AppOptions options;
  options.warn_before_quitting = true;
  App::init(options, [](std::shared_ptr<App> app) {
    // Work with the app here.
  });
}

Language

This option configures the language used on the default error pages and the message dialogs. By default, the language of the application is set to English. You can change it to any other supported language as follows:

options.ui_language = UiLanguage::kUkrainian;

Here’s the list of supported languages:

Language Enum item
Amharic kAmharic
Arabic kArabic
Bengali kBengali
Bulgarian kBulgarian
Catalan kCatalan
Chinese (PRC) kChinese
Chinese (Taiwan) kChineseTaiwan
Czech kCzech
Danish kDanish
German kGerman
Greek kGreek
English (US) kEnglishUs
English (UK) kEnglishUk
Spanish (Latin America) kSpanishLatinAmerica
Spanish (Spain) kSpanishSpain
Estonian kEstonian
Persian kPersian
Finnish kFinnish
Filipino kFilipino
French kFrench
Gujarati kGujarati
Hebrew kHebrew
Hindi kHindi
Croatian kCroatian
Hungarian kHungarian
Indonesian kIndonesian
Italian kItalian
Japanese kJapanese
Kannada kKannada
Korean kKorean
Lithuanian kLithuanian
Latvian kLatvian
Malayalam kMalayalam
Marathi kMarathi
Malay kMalay
Norwegian kNorwegian
Dutch kDutch
Polish kPolish
Portuguese (Brazil) kPortugueseBrazil
Portuguese (Portugal) kPortuguesePortugal
Romanian kRomanian
Russian kRussian
Slovak kSlovak
Slovenian kSlovenian
Serbian kSerbian
Swedish kSwedish
Swahili kSwahili
Tamil kTamil
Telugu kTelugu
Thai kThai
Turkish kTurkish
Ukrainian kUkrainian
Vietnamese kVietnamese

I18N internationalization

Molybden even supports I18N internationalization when browsing local file system.

User data directory

The user data directory is a folder where the application stores user-specific data such as profiles, settings, cache, cookies, local storage, visited links, web data, spell checking dictionaries, and other browsing data.

The exact location of the user data directory depends on the operating system and application name:

  • On Windows: C:\Users\<USER_NAME>\AppData\Local\<APP_NAME>\User Data\
  • On macOS: /Users/<USER_NAME>/Library/Application Support/<APP_NAME>/
  • On Linux: /home/<USER_NAME>/.config/<APP_NAME>/

You can change the default location of the user data directory as follows:

options.user_data_dir = "/path/to/user/data/dir";

Important: Make sure that the application has permissions to write to the specified directory and the directory is not located on a network drive.

Warn before quitting

This options enables or disables the warning dialog that appears when the user tries to quit the application via Cmd+Q on macOS. By default, the warning dialog is disabled. You can enable it as follows:

options.warn_before_quitting = true;

This option is applicable only at the first application run. After, the user may uncheck the “Warn Before Quitting ( Cmd+Q)” application menu item and the application will preserve it for the future runs.

Quit when last window is closed

This options enables or disables the application quit when the last browser window is closed. By default, this options is enabled. You can disable it as follows:

options.quit_when_last_browser_closed = false;

Proprietary codecs and Widevine

By default, the H.264 and AAC proprietary codecs and Widevine DRM are disabled.

In order to support the H.264 and AAC proprietary codecs in your application, you need to acquire appropriate licenses and enable them as follows:

options.enable_aac = true;
options.enable_h264 = true;

Important: The H.264 and AAC codecs are the proprietary components. By enabling these codecs you state that you are aware that H.264 and AAC are the proprietary components, and you should have a license in order to use them. For more information, you could contact patent holders: Via Licensing and MPEG LA. TeamDev shall not be responsible for your use of the H.264 and AAC codecs.

The web services like Netflix or Amazon Prime use Widevine to distribute their DRM-encoded content. Widevine is a Google proprietary component that is disabled by default. In order to enable it and play the DRM-encoded content, use the following approach:

options.enable_widevine = true;

Widevine works on Windows and macOS only. On Linux, it is not supported.

Important: Widevine is a Google proprietary component, governed by its own terms of use. For more information, see www.widevine.com.

Remote debugging port

This option sets the Chromium remote debugging port. You may need it to integrate with software like Selenium that relies on Chrome DevTools Protocol.

To set the remote debugging port, use the following approach:

options.remote_debugging_port = 9222;

This option enables remote debugging over HTTP at the specific port. When remote debugging is enabled, you can load the chrome://inspect/#devices address in Google Chrome and debug the loaded web pages using Chrome DevTools.

Chrome inspect page

Disabling GPU

This option disables the GPU acceleration. You may need it to run the application on the virtual machine or in the remote desktop session. To disable the GPU acceleration, use the following approach:

options.disable_gpu = true;

Incognito mode

This option enables or disables the incognito mode for the default profile. By default, it’s disabled.

In the incognito mode the user data such as browsing history, cookies, site data, and the information entered in forms are stored in memory and released once you terminate the application. The option affects the type of the default profile only.

To enable the incognito mode for the default profile, use the following approach:

options.enable_incognito = true;

Logging

The logging option allow you to configure the logging behavior of the application.

Read more about how to configure logging in the Logging section.

User-agent

Using this option you can configure the default user agent string. You might want to use it to emulate the user agent of a specific browser or tell the web page that it’s displayed inside your desktop application.

To change the default user agent string, use the following approach:

options.user_agent = "My custom user agent string";

Important: Be careful when changing the user agent string. Some web pages may not work properly if they detect that the user agent string is not the one they expect.

Schemes

The schemes option allows you to register custom URL schemes. You can use it to intercept URL requests with the custom schemes and provide the response data from the local file system or memory.

Read more about how to register custom URL schemes in the Schemes section.

Chromium switches

Molybden is based on the Chromium engine. Chromium accepts the command line switches that change its behavior, allow to debug, or turn the experimental features on.

For the list of switches and their description you can find in the documentation provided by Peter Beverloo.

To configure Chromium with the required switches use the following approach:

options.switches.insert("--<switch-name>");
options.switches.insert("--<switch-name>=<switch-value>");

Terminating application

You can terminate the application manually or programmatically.

To terminate the application programmatically, use the following approach:

app->quit();

Restarting application

You can restart the application programmatically. To do this, use the following approach:

app->restart();

It will close all application windows, release the allocated resources, terminate the application process, and then run the application again with the same command line arguments.

Application details

You may want to show the current application name, version, description, or copyright in the “About” dialog or in the “ Help” menu. To get this information programmatically you can use the following API:

std::string app_name = app->name();
std::string app_version = app->version();
std::string app_description = app->description();
std::string copyright = app->copyright();

These application details are taken from the molybden.conf.json file located in the root directory of your project. If you want to change them, then just edit the molybden.conf.json file and then run or build the app.

Resources directory

The resources directory is a folder where the application stores its resources such as images, configuration files, etc. It is located in the src-cpp/resources directory of your project.

All the files and folders from the resources directory will be copied to the application bundle. To get the absolute path to the resources directory inside the application bundle, use the following approach:

std::string path_to_resources = app->getPath(PathKey::kAppResources);
On this page
Top