Chrome extension windows create

How to Create Chrome Extensions

Step by step tutorial on how to build your custom google chrome extension.

What are extensions? ⚙️

Extensions are small software programs that customize the browsing experience. They enable users to tailor Chrome functionality and behavior to individual preferences. They are built on web technologies such as HTML, JS, and CSS.

An extension must fulfil a single purpose that is narrowly defined and easy to understand. A single extension can include multiple components and a range of functionality, as long as everything contributes towards a common purpose.

Here are some example extensions, that are not currently present on Chrome and are not downloadable within the Extension Store, but can be added with a little bit of tinkering:

Usually, Chrome users just download their commonly needed extensions from the Extension Store, but some extensions are outdated and none functional.

How to create an extension? 🛠

We will start by creating a folder with these files:

1) manifest.json

The manifest.json file tells Chrome important information about your extension, like its name and which permissions it needs.

Now within the manifest file, all variables can be changed and most of them are self-explanatory. The matches variable will run the select content.js when a certain webpage has been opened, for example:

Or follow this little cheat sheet:

2) content.js

A content.js script is “a JavaScript file that runs in the context of web pages.” This means that a content script can interact with web pages that the browser visits.

3) Image Icon

Download an icon png file and place it within the created folder, you can download one here LINK .

4) background.js

Although the extension has been installed, it has no instruction. Introduce a background script by creating a file titled background.js and placing it inside the extension directory.

Background scripts and many other components must be registered in the manifest. Registering a background script in the manifest tells the extension which files to reference, and how that file will behave.

Now place all those four files within a folder. The folder must be named to whatever you want to call your extension. If done correctly your folder should look ← like this

chrome.app.window

Use the chrome.app.window API to create windows. Windows have an optional frame with title bar and size controls. They are not associated with any Chrome browser windows. See the Window State Sample for a demonstration of these options.

Summary

Types

AppWindow

Properties

Clear attention to the window.

The clearAttention function looks like this:

Close the window.

The close function looks like this:

The JavaScript ‘window’ object for the created child.

Draw attention to the window.

The drawAttention function looks like this:

Focus the window.

The focus function looks like this:

Fullscreens the window.

The user will be able to restore the window by pressing ESC. An application can prevent the fullscreen state to be left when ESC is pressed by requesting the app.window.fullscreen.overrideEsc permission and canceling the event by calling .preventDefault(), in the keydown and keyup handlers, like this:

Note window.fullscreen() will cause the entire window to become fullscreen and does not require a user gesture. The HTML5 fullscreen API can also be used to enter fullscreen mode (see Web APIs for more details).

Читайте также:  How to delete one windows

The fullscreen function looks like this:

Deprecated. Use innerBounds or outerBounds.

Get the window’s inner bounds as a ContentBounds object.

The getBounds function looks like this:

Hide the window. Does nothing if the window is already hidden.

The hide function looks like this:

The id the window was created with.

The position, size and constraints of the window’s content, which does not include window decorations. This property is new in Chrome 36.

Is the window always on top?

The isAlwaysOnTop function looks like this:

Is the window fullscreen? This will be true if the window has been created fullscreen or was made fullscreen via the AppWindow or HTML5 fullscreen APIs.

The isFullscreen function looks like this:

Is the window maximized?

The isMaximized function looks like this:

Is the window minimized?

The isMinimized function looks like this:

Maximize the window.

The maximize function looks like this:

Minimize the window.

The minimize function looks like this:

Deprecated. Use outerBounds.

Move the window to the position ( left , top ).

The moveTo function looks like this:

The position, size and constraints of the window, which includes window decorations, such as the title bar and frame. This property is new in Chrome 36.

Deprecated. Use outerBounds.

Resize the window to width x height pixels in size.

The resizeTo function looks like this:

Restore the window, exiting a maximized, minimized, or fullscreen state.

The restore function looks like this:

Set whether the window should stay above most other windows. Requires the alwaysOnTopWindows permission.

The setAlwaysOnTop function looks like this:

Deprecated. Use innerBounds or outerBounds.

Set the window’s inner bounds.

The setBounds function looks like this:

Set whether the window is visible on all workspaces. (Only for platforms that support this).

The setVisibleOnAllWorkspaces function looks like this:

Show the window. Does nothing if the window is already visible. Focus the window if focused is set to true or omitted.

The show function looks like this:

Bounds

Properties

This property can be used to read or write the current height of the content or window.

This property can be used to read or write the current X coordinate of the content or window.

This property can be used to read or write the current maximum height of the content or window. A value of null indicates ‘unspecified’.

This property can be used to read or write the current maximum width of the content or window. A value of null indicates ‘unspecified’.

This property can be used to read or write the current minimum height of the content or window. A value of null indicates ‘unspecified’.

This property can be used to read or write the current minimum width of the content or window. A value of null indicates ‘unspecified’.

Set the maximum size constraints of the content or window. The maximum width or height can be set to null to remove the constraint. A value of undefined will leave a constraint unchanged.

The setMaximumSize function looks like this:

Set the minimum size constraints of the content or window. The minimum width or height can be set to null to remove the constraint. A value of undefined will leave a constraint unchanged.

The setMinimumSize function looks like this:

Set the left and top position of the content or window.

The setPosition function looks like this:

Set the width and height of the content or window.

The setSize function looks like this:

This property can be used to read or write the current Y coordinate of the content or window.

Читайте также:  Install system windows media

This property can be used to read or write the current width of the content or window.

BoundsSpecification

Properties

The height of the content or window.

The X coordinate of the content or window.

The maximum height of the content or window.

The maximum width of the content or window.

The minimum height of the content or window.

The minimum width of the content or window.

The Y coordinate of the content or window.

The width of the content or window.

ContentBounds

Properties

CreateWindowOptions

Properties

If true, the window will stay above most other windows. If there are multiple windows of this kind, the currently focused window will be in the foreground. Requires the alwaysOnTopWindows permission. Defaults to false.

Call setAlwaysOnTop() on the window to change this property after creation.

Deprecated. Use innerBounds or outerBounds.

Size and position of the content in the window (excluding the titlebar). If an id is also specified and a window with a matching id has been shown before, the remembered bounds of the window will be used instead.

If true, the window will be focused when created. Defaults to true.

Frame type: none or chrome (defaults to chrome ). For none , the -webkit-app-region CSS property can be used to apply draggability to the app’s window. -webkit-app-region: drag can be used to mark regions draggable. no-drag can be used to disable this style on nested elements.

Use of FrameOptions is new in M36.

If true, the window will be created in a hidden state. Call show() on the window to show it once it has been created. Defaults to false.

Since Chrome 54.

URL of the window icon. A window can have its own icon when showInShelf is set to true. The URL should be a global or an extension local URL.

Id to identify the window. This will be used to remember the size and position of the window and restore that geometry when a window with the same id is later opened. If a window with a given id is created while another window with the same id already exists, the currently opened window will be focused instead of creating a new window.

Used to specify the initial position, initial size and constraints of the window’s content (excluding window decorations). If an id is also specified and a window with a matching id has been shown before, the remembered bounds will be used instead.

Note that the padding between the inner and outer bounds is determined by the OS. Therefore setting the same bounds property for both the innerBounds and outerBounds will result in an error.

This property is new in Chrome 36.

Deprecated. Use innerBounds or outerBounds.

Maximum height of the window.

Deprecated. Use innerBounds or outerBounds.

Maximum width of the window.

Deprecated. Use innerBounds or outerBounds.

Minimum height of the window.

Deprecated. Use innerBounds or outerBounds.

Minimum width of the window.

Used to specify the initial position, initial size and constraints of the window (including window decorations such as the title bar and frame). If an id is also specified and a window with a matching id has been shown before, the remembered bounds will be used instead.

Note that the padding between the inner and outer bounds is determined by the OS. Therefore setting the same bounds property for both the innerBounds and outerBounds will result in an error.

This property is new in Chrome 36.

If true, the window will be resizable by the user. Defaults to true.

Читайте также:  Курсоры мыши minecraft для windows

Since Chrome 54.

If true, the window will have its own shelf icon. Otherwise the window will be grouped in the shelf with other windows that are associated with the app. Defaults to false. If showInShelf is set to true you need to specify an id for the window.

Deprecated. Multiple windows with the same id is no longer supported.

By default if you specify an id for the window, the window will only be created if another window with the same id doesn’t already exist. If a window with the same id already exists that window is activated instead. If you do want to create multiple windows with the same id, you can set this property to false.

The initial state of the window, allowing it to be created already fullscreen, maximized, or minimized. Defaults to ‘normal’.

Since Chrome 45.

Deprecated since Chrome 69. All app windows use the ‘shell’ window type

Type of window to create.

If true, and supported by the platform, the window will be visible on all workspaces.

FrameOptions

Properties

Allows the frame color of the window when active to be set. Frame coloring is only available if the frame type is chrome .

Frame coloring is only available if the frame type is chrome .

Frame coloring is new in Chrome 36.

Allows the frame color to be set. Frame coloring is only available if the frame type is chrome .

Frame coloring is new in Chrome 36.

Allows the frame color of the window when inactive to be set differently to the active color. Frame coloring is only available if the frame type is chrome .

inactiveColor must be used in conjunction with color .

Frame coloring is new in Chrome 36.

Frame type: none or chrome (defaults to chrome ).

For none , the -webkit-app-region CSS property can be used to apply draggability to the app’s window.

-webkit-app-region: drag can be used to mark regions draggable. no-drag can be used to disable this style on nested elements.

State

State of a window: normal, fullscreen, maximized, minimized.

«normal» , «fullscreen» , «maximized» , or «minimized»

WindowType

Since Chrome 45.

Specifies the type of window to create.

«shell» , or «panel»

Methods

canSetVisibleOnAllWorkspaces

Whether the current platform supports windows being visible on all workspaces.

Returns

create

The size and position of a window can be specified in a number of different ways. The most simple option is not specifying anything at all, in which case a default size and platform dependent position will be used.

To set the position, size and constraints of the window, use the innerBounds or outerBounds properties. Inner bounds do not include window decorations. Outer bounds include the window’s title bar and frame. Note that the padding between the inner and outer bounds is determined by the OS. Therefore setting the same property for both inner and outer bounds is considered an error (for example, setting both innerBounds.left and outerBounds.left ).

To automatically remember the positions of windows you can give them ids. If a window has an id, This id is used to remember the size and position of the window whenever it is moved or resized. This size and position is then used instead of the specified bounds on subsequent opening of a window with the same id. If you need to open a window with an id at a location other than the remembered default, you can create it hidden, move it to the desired location, then show it.

Оцените статью